Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::rml::private_worker Class Reference
Inheritance diagram for tbb::internal::rml::private_worker:
Collaboration diagram for tbb::internal::rml::private_worker:

Protected Member Functions

 private_worker (private_server &server, tbb_client &client, const size_t i)
 

Private Types

enum  state_t { st_init, st_starting, st_normal, st_quit }
 State in finite-state machine that controls the worker. More...
 

Private Member Functions

void run ()
 Actions executed by the associated thread. More...
 
void wake_or_launch ()
 Wake up associated thread (or launch a thread if there is none) More...
 
void start_shutdown ()
 Called by a thread (usually not the associated thread) to commence termination. More...
 
- Private Member Functions inherited from tbb::internal::no_copy
 no_copy (const no_copy &)=delete
 
 no_copy ()=default
 

Static Private Member Functions

static __RML_DECL_THREAD_ROUTINE thread_routine (void *arg)
 
static void release_handle (thread_handle my_handle, bool join)
 

Private Attributes

atomic< state_tmy_state
 
private_servermy_server
 Associated server. More...
 
tbb_client & my_client
 Associated client. More...
 
const size_t my_index
 index used for avoiding the 64K aliasing problem More...
 
thread_monitor my_thread_monitor
 Monitor for sleeping when there is no work to do. More...
 
thread_handle my_handle
 Handle of the OS thread associated with this worker. More...
 
private_workermy_next
 Link for list of workers that are sleeping or have no associated thread. More...
 

Friends

class private_server
 

Detailed Description

Definition at line 35 of file private_server.cpp.

Member Enumeration Documentation

◆ state_t

State in finite-state machine that controls the worker.

State diagram: init --> starting --> normal | | | | V | ---—> quit <---—/

Enumerator
st_init 

*this is initialized

st_starting 

*this has associated thread that is starting up.

st_normal 

Associated thread is doing normal life sequence.

st_quit 

Associated thread has ended normal life sequence and promises to never touch *this again.

Definition at line 44 of file private_server.cpp.

44  {
46  st_init,
50  st_normal,
52  st_quit
53  };
*this has associated thread that is starting up.
Associated thread is doing normal life sequence.
Associated thread has ended normal life sequence and promises to never touch *this again.

Constructor & Destructor Documentation

◆ private_worker()

tbb::internal::rml::private_worker::private_worker ( private_server server,
tbb_client &  client,
const size_t  i 
)
inlineprotected

Definition at line 92 of file private_server.cpp.

92  :
93  my_server(server), my_client(client), my_index(i),
95  {
96  my_state = st_init;
97  }
thread_monitor my_thread_monitor
Monitor for sleeping when there is no work to do.
const size_t my_index
index used for avoiding the 64K aliasing problem
private_server & my_server
Associated server.
tbb_client & my_client
Associated client.
private_worker * my_next
Link for list of workers that are sleeping or have no associated thread.
thread_handle my_handle
Handle of the OS thread associated with this worker.

References my_state, and st_init.

Member Function Documentation

◆ release_handle()

void tbb::internal::rml::private_worker::release_handle ( thread_handle  my_handle,
bool  join 
)
staticprivate

Definition at line 226 of file private_server.cpp.

226  {
227  if (join)
228  thread_monitor::join(handle);
229  else
230  thread_monitor::detach_thread(handle);
231 }

Referenced by start_shutdown(), and wake_or_launch().

Here is the caller graph for this function:

◆ run()

void tbb::internal::rml::private_worker::run ( )
private

Actions executed by the associated thread.

Definition at line 256 of file private_server.cpp.

256  {
258 
259  // Transiting to st_normal here would require setting my_handle,
260  // which would create race with the launching thread and
261  // complications in handle management on Windows.
262 
263  ::rml::job& j = *my_client.create_one_job();
264  while( my_state!=st_quit ) {
265  if( my_server.my_slack>=0 ) {
266  my_client.process(j);
267  } else {
268  thread_monitor::cookie c;
269  // Prepare to wait
270  my_thread_monitor.prepare_wait(c);
271  // Check/set the invariant for sleeping
273  my_thread_monitor.commit_wait(c);
274  __TBB_ASSERT( my_state==st_quit || !my_next, "Thread monitor missed a spurious wakeup?" );
276  } else {
277  // Invariant broken
278  my_thread_monitor.cancel_wait();
279  }
280  }
281  }
282  my_client.cleanup(j);
283 
286 }
thread_monitor my_thread_monitor
Monitor for sleeping when there is no work to do.
private_server & my_server
Associated server.
tbb_client & my_client
Associated client.
Associated thread has ended normal life sequence and promises to never touch *this again.
private_worker * my_next
Link for list of workers that are sleeping or have no associated thread.
bool try_insert_in_asleep_list(private_worker &t)
Try to add t to list of sleeping workers.
void propagate_chain_reaction()
Wake up to two sleeping workers, if there are any sleeping.
atomic< int > my_slack
Number of jobs that could use their associated thread minus number of active threads.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

References __TBB_ASSERT, my_client, my_next, my_server, tbb::internal::rml::private_server::my_slack, my_state, my_thread_monitor, tbb::internal::rml::private_server::propagate_chain_reaction(), tbb::internal::rml::private_server::remove_server_ref(), st_quit, and tbb::internal::rml::private_server::try_insert_in_asleep_list().

Here is the call graph for this function:

◆ start_shutdown()

void tbb::internal::rml::private_worker::start_shutdown ( )
private

Called by a thread (usually not the associated thread) to commence termination.

Definition at line 233 of file private_server.cpp.

233  {
234  state_t s;
235 
236  do {
237  s = my_state;
238  __TBB_ASSERT( s!=st_quit, NULL );
239  } while( my_state.compare_and_swap( st_quit, s )!=s );
240  if( s==st_normal || s==st_starting ) {
241  // May have invalidated invariant for sleeping, so wake up the thread.
242  // Note that the notify() here occurs without maintaining invariants for my_slack.
243  // It does not matter, because my_state==st_quit overrides checking of my_slack.
244  my_thread_monitor.notify();
245  // Do not need release handle in st_init state,
246  // because in this case the thread wasn't started yet.
247  // For st_starting release is done at launch site.
248  if (s==st_normal)
250  } else if( s==st_init ) {
251  // Perform action that otherwise would be performed by associated thread when it quits.
253  }
254 }
thread_monitor my_thread_monitor
Monitor for sleeping when there is no work to do.
*this has associated thread that is starting up.
private_server & my_server
Associated server.
Associated thread is doing normal life sequence.
tbb_client & my_client
Associated client.
Associated thread has ended normal life sequence and promises to never touch *this again.
static bool does_client_join_workers(const tbb::internal::rml::tbb_client &client)
Definition: market.cpp:304
static void release_handle(thread_handle my_handle, bool join)
state_t
State in finite-state machine that controls the worker.
thread_handle my_handle
Handle of the OS thread associated with this worker.
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

References __TBB_ASSERT, tbb::internal::governor::does_client_join_workers(), my_client, my_handle, my_server, my_state, my_thread_monitor, release_handle(), tbb::internal::rml::private_server::remove_server_ref(), s, st_init, st_normal, st_quit, and st_starting.

Here is the call graph for this function:

◆ thread_routine()

__RML_DECL_THREAD_ROUTINE tbb::internal::rml::private_worker::thread_routine ( void arg)
staticprivate

Definition at line 216 of file private_server.cpp.

216  {
217  private_worker* self = static_cast<private_worker*>(arg);
218  AVOID_64K_ALIASING( self->my_index );
219  self->run();
220  return 0;
221 }
private_worker(private_server &server, tbb_client &client, const size_t i)

Referenced by wake_or_launch().

Here is the caller graph for this function:

◆ wake_or_launch()

void tbb::internal::rml::private_worker::wake_or_launch ( )
inlineprivate

Wake up associated thread (or launch a thread if there is none)

Definition at line 288 of file private_server.cpp.

288  {
289  if( my_state==st_init && my_state.compare_and_swap( st_starting, st_init )==st_init ) {
290  // after this point, remove_server_ref() must be done by created thread
291 #if USE_WINTHREAD
292  my_handle = thread_monitor::launch( thread_routine, this, my_server.my_stack_size, &this->my_index );
293 #elif USE_PTHREAD
294  {
295  affinity_helper fpa;
296  fpa.protect_affinity_mask( /*restore_process_mask=*/true );
297  my_handle = thread_monitor::launch( thread_routine, this, my_server.my_stack_size );
298  // Implicit destruction of fpa resets original affinity mask.
299  }
300 #endif /* USE_PTHREAD */
301  state_t s = my_state.compare_and_swap( st_normal, st_starting );
302  if (st_starting != s) {
303  // Do shutdown during startup. my_handle can't be released
304  // by start_shutdown, because my_handle value might be not set yet
305  // at time of transition from st_starting to st_quit.
306  __TBB_ASSERT( s==st_quit, NULL );
308  }
309  }
310  else {
311  __TBB_ASSERT( !my_next, "Should not wake a thread while it's still in asleep list" );
312  my_thread_monitor.notify();
313  }
314 }
thread_monitor my_thread_monitor
Monitor for sleeping when there is no work to do.
const size_t my_stack_size
Stack size for each thread. */.
*this has associated thread that is starting up.
private_server & my_server
Associated server.
Associated thread is doing normal life sequence.
tbb_client & my_client
Associated client.
Associated thread has ended normal life sequence and promises to never touch *this again.
private_worker * my_next
Link for list of workers that are sleeping or have no associated thread.
static bool does_client_join_workers(const tbb::internal::rml::tbb_client &client)
Definition: market.cpp:304
static __RML_DECL_THREAD_ROUTINE thread_routine(void *arg)
static void release_handle(thread_handle my_handle, bool join)
state_t
State in finite-state machine that controls the worker.
thread_handle my_handle
Handle of the OS thread associated with this worker.
void const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

References __TBB_ASSERT, tbb::internal::governor::does_client_join_workers(), my_client, my_handle, my_next, my_server, tbb::internal::rml::private_server::my_stack_size, my_state, my_thread_monitor, tbb::internal::affinity_helper::protect_affinity_mask(), release_handle(), s, st_init, st_normal, st_quit, st_starting, and thread_routine().

Referenced by tbb::internal::rml::private_server::wake_some().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ private_server

friend class private_server
friend

Definition at line 76 of file private_server.cpp.

Member Data Documentation

◆ my_client

tbb_client& tbb::internal::rml::private_worker::my_client
private

Associated client.

Definition at line 60 of file private_server.cpp.

Referenced by run(), start_shutdown(), and wake_or_launch().

◆ my_handle

thread_handle tbb::internal::rml::private_worker::my_handle
private

Handle of the OS thread associated with this worker.

Definition at line 71 of file private_server.cpp.

Referenced by start_shutdown(), and wake_or_launch().

◆ my_index

const size_t tbb::internal::rml::private_worker::my_index
private

index used for avoiding the 64K aliasing problem

Definition at line 63 of file private_server.cpp.

◆ my_next

private_worker* tbb::internal::rml::private_worker::my_next
private

◆ my_server

private_server& tbb::internal::rml::private_worker::my_server
private

Associated server.

Definition at line 57 of file private_server.cpp.

Referenced by run(), start_shutdown(), and wake_or_launch().

◆ my_state

atomic<state_t> tbb::internal::rml::private_worker::my_state
private

Definition at line 54 of file private_server.cpp.

Referenced by private_worker(), run(), start_shutdown(), and wake_or_launch().

◆ my_thread_monitor

thread_monitor tbb::internal::rml::private_worker::my_thread_monitor
private

Monitor for sleeping when there is no work to do.

The invariant that holds for sleeping workers is: "my_slack<=0 && my_state==st_normal && I am on server's list of asleep threads"

Definition at line 68 of file private_server.cpp.

Referenced by run(), start_shutdown(), and wake_or_launch().


The documentation for this class was generated from the following file:

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.