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 ()
 Allow default construction. More...
 

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 39 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 48 of file private_server.cpp.

48  {
50  st_init,
54  st_normal,
56  st_quit
57  };
Associated thread has ended normal life sequence and promises to never touch *this again.
*this has associated thread that is starting up.
Associated thread is doing normal life sequence.

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 96 of file private_server.cpp.

96  :
97  my_server(server), my_client(client), my_index(i),
99  {
100  my_state = st_init;
101  }
tbb_client & my_client
Associated client.
const size_t my_index
index used for avoiding the 64K aliasing problem
private_server & my_server
Associated server.
private_worker * my_next
Link for list of workers that are sleeping or have no associated thread.
thread_monitor my_thread_monitor
Monitor for sleeping when there is no work to do.
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 230 of file private_server.cpp.

230  {
231  if (join)
232  thread_monitor::join(handle);
233  else
234  thread_monitor::detach_thread(handle);
235 }

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 260 of file private_server.cpp.

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

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 237 of file private_server.cpp.

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

References __TBB_ASSERT, tbb::internal::atomic_impl< T >::compare_and_swap(), 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 220 of file private_server.cpp.

220  {
221  private_worker* self = static_cast<private_worker*>(arg);
222  AVOID_64K_ALIASING( self->my_index );
223  self->run();
224  return 0;
225 }
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 292 of file private_server.cpp.

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

References __TBB_ASSERT, tbb::internal::atomic_impl< T >::compare_and_swap(), 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 80 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 64 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 75 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 67 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 61 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 58 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 72 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-2019 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.