LCOV - code coverage report
Current view: top level - atermpp/test - parallel_container_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 16 17 94.1 %
Date: 2024-05-04 03:44:52 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Maurice Laveaux
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : 
      10             : #define BOOST_TEST_MODULE parallel_test
      11             : #include <boost/test/included/unit_test.hpp>
      12             : 
      13             : #include "mcrl2/utilities/configuration.h"
      14             : #include "mcrl2/atermpp/aterm_int.h"
      15             : #include "mcrl2/atermpp/standard_containers/vector.h"
      16             : #include "mcrl2/atermpp/detail/global_aterm_pool.h"
      17             : 
      18             : #include <thread>
      19             : 
      20             : using namespace atermpp;
      21             : 
      22           2 : BOOST_AUTO_TEST_CASE(parallel_vector, *boost::unit_test::timeout(240))
      23             : {
      24             :   if constexpr (mcrl2::utilities::detail::GlobalThreadSafe)
      25             :   {
      26             :     // One thread continuously modifies a local atermpp::vector of aterms while the main thread performs garbage collection extensively.
      27           1 :     std::thread local([]() 
      28             :     {
      29             :       // Push a constant to avoid term creations.
      30           1 :       atermpp::aterm_int value(0);
      31             : 
      32       10001 :       for (std::size_t i = 0; i < 10000; ++i)
      33             :       {
      34       10000 :         atermpp::vector<atermpp::aterm> vector;
      35   100010000 :         for (std::size_t i = 0; i < 10000; ++i)
      36             :         {
      37   100000000 :           vector.push_back(value);
      38             :         }
      39       10000 :       }
      40           2 :     });
      41             : 
      42             :     while (true)
      43             :     {
      44        1001 :       for (std::size_t i = 0; i < 1000; ++i)
      45             :       {
      46        1000 :         atermpp::detail::g_thread_term_pool().collect();
      47             :       }
      48             : 
      49           1 :       if (local.joinable())
      50             :       {
      51           1 :         local.join();
      52           1 :         break;
      53             :       }
      54           0 :     }
      55           1 :   }
      56           1 : }
      57             : 

Generated by: LCOV version 1.14