The Gaudi Framework  master (da3d77e1)
FiberManager.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 
12 #include "FiberManager.h"
13 
16  auto* main_algo_ptr = new SchedAlgo( true );
17  m_schedAlgoList.at( n_threads ) = main_algo_ptr;
18 #if ( BOOST_VERSION >= 108400 )
19  boost::fibers::initialize_thread( main_algo_ptr,
20  boost::fibers::make_stack_allocator_wrapper<boost::fibers::default_stack>() );
21 #else
22  boost::fibers::context::active()->get_scheduler()->set_algo( main_algo_ptr );
23 #endif
24 
25  for ( int i = 0; i < n_threads; ++i ) {
26  m_threads.emplace_back( std::thread( [this, i]() {
27  auto* algo_ptr = new SchedAlgo( true );
28  m_schedAlgoList.at( i ) = algo_ptr;
29 #if ( BOOST_VERSION >= 108400 )
30  boost::fibers::initialize_thread( algo_ptr,
31  boost::fibers::make_stack_allocator_wrapper<boost::fibers::default_stack>() );
32 #else
33  boost::fibers::context::active()->get_scheduler()->set_algo( algo_ptr );
34 #endif
36  m_shuttingDown_cv.wait( lck );
37  } ) );
38  }
39 }
40 
42  m_shuttingDown_cv.notify_all();
43  for ( std::thread& t : m_threads ) { t.join(); }
44 }
std::vector::resize
T resize(T... args)
FiberManager::m_threads
std::vector< std::thread > m_threads
Definition: FiberManager.h:63
prepareBenchmark.n_threads
n_threads
Definition: prepareBenchmark.py:40
FiberManager::~FiberManager
~FiberManager()
Definition: FiberManager.cpp:41
FiberManager::m_schedAlgoList
std::vector< SchedAlgo * > m_schedAlgoList
Definition: FiberManager.h:64
bug_34121.t
t
Definition: bug_34121.py:31
FiberManager::SchedAlgo
boost::fibers::algo::shared_work SchedAlgo
Definition: FiberManager.h:60
std::thread
STL class.
std::vector::at
T at(T... args)
std::unique_lock
STL class.
FiberManager::FiberManager
FiberManager(int n_threads)
FiberManager constructor.
Definition: FiberManager.cpp:14
FiberManager::m_shuttingDown_mtx
boost::fibers::mutex m_shuttingDown_mtx
Definition: FiberManager.h:62
std::vector::emplace_back
T emplace_back(T... args)
FiberManager.h
FiberManager::m_shuttingDown_cv
boost::fibers::condition_variable m_shuttingDown_cv
Definition: FiberManager.h:61