Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::tbb_thread_v3 Class Reference

Versioned thread class. More...

#include <tbb_thread.h>

Collaboration diagram for tbb::internal::tbb_thread_v3:

Classes

class  id
 

Public Types

typedef pthread_t native_handle_type
 

Public Member Functions

 tbb_thread_v3 () __TBB_NOEXCEPT(true)
 Constructs a thread object that does not represent a thread of execution. More...
 
template<class F >
 tbb_thread_v3 (F f)
 Constructs an object and executes f() in a new thread. More...
 
template<class F , class X >
 tbb_thread_v3 (F f, X x)
 Constructs an object and executes f(x) in a new thread. More...
 
template<class F , class X , class Y >
 tbb_thread_v3 (F f, X x, Y y)
 Constructs an object and executes f(x,y) in a new thread. More...
 
 tbb_thread_v3 (tbb_thread_v3 &&x) __TBB_NOEXCEPT(true)
 
tbb_thread_v3operator= (tbb_thread_v3 &&x) __TBB_NOEXCEPT(true)
 
void swap (tbb_thread_v3 &t) __TBB_NOEXCEPT(true)
 
bool joinable () const __TBB_NOEXCEPT(true)
 
void __TBB_EXPORTED_METHOD join ()
 The completion of the thread represented by *this happens before join() returns. More...
 
void __TBB_EXPORTED_METHOD detach ()
 When detach() returns, *this no longer represents the possibly continuing thread of execution. More...
 
 ~tbb_thread_v3 ()
 
id get_id () const __TBB_NOEXCEPT(true)
 
native_handle_type native_handle ()
 

Static Public Member Functions

static unsigned __TBB_EXPORTED_FUNC hardware_concurrency () __TBB_NOEXCEPT(true)
 The number of hardware thread contexts. More...
 

Private Member Functions

 tbb_thread_v3 (const tbb_thread_v3 &)
 
tbb_thread_v3operator= (const tbb_thread_v3 &x)
 
void internal_wipe () __TBB_NOEXCEPT(true)
 
void internal_move (tbb_thread_v3 &x) __TBB_NOEXCEPT(true)
 
void __TBB_EXPORTED_METHOD internal_start (__TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine), void *closure)
 

Private Attributes

native_handle_type my_handle
 

Friends

void __TBB_EXPORTED_FUNC move_v3 (tbb_thread_v3 &t1, tbb_thread_v3 &t2)
 
void tbb::swap (tbb_thread_v3 &t1, tbb_thread_v3 &t2) __TBB_NOEXCEPT(true)
 

Detailed Description

Versioned thread class.

Definition at line 112 of file tbb_thread.h.

Member Typedef Documentation

◆ native_handle_type

Definition at line 124 of file tbb_thread.h.

Constructor & Destructor Documentation

◆ tbb_thread_v3() [1/6]

tbb::internal::tbb_thread_v3::tbb_thread_v3 ( const tbb_thread_v3 )
private

◆ tbb_thread_v3() [2/6]

tbb::internal::tbb_thread_v3::tbb_thread_v3 ( )
inline

Constructs a thread object that does not represent a thread of execution.

Definition at line 129 of file tbb_thread.h.

129  : my_handle(0)
130 #if _WIN32||_WIN64
131  , my_thread_id(0)
132 #endif // _WIN32||_WIN64
133  {}
native_handle_type my_handle
Definition: tbb_thread.h:196

◆ tbb_thread_v3() [3/6]

template<class F >
tbb::internal::tbb_thread_v3::tbb_thread_v3 ( f)
inlineexplicit

Constructs an object and executes f() in a new thread.

Definition at line 136 of file tbb_thread.h.

136  {
137  typedef internal::thread_closure_0<F> closure_type;
138  internal_start(closure_type::start_routine, new closure_type(f));
139  }
void __TBB_EXPORTED_METHOD internal_start(__TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine), void *closure)
Definition: tbb_thread.cpp:94

◆ tbb_thread_v3() [4/6]

template<class F , class X >
tbb::internal::tbb_thread_v3::tbb_thread_v3 ( f,
x 
)
inline

Constructs an object and executes f(x) in a new thread.

Definition at line 141 of file tbb_thread.h.

141  {
142  typedef internal::thread_closure_1<F,X> closure_type;
143  internal_start(closure_type::start_routine, new closure_type(f,x));
144  }
void __TBB_EXPORTED_METHOD internal_start(__TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine), void *closure)
Definition: tbb_thread.cpp:94

◆ tbb_thread_v3() [5/6]

template<class F , class X , class Y >
tbb::internal::tbb_thread_v3::tbb_thread_v3 ( f,
x,
y 
)
inline

Constructs an object and executes f(x,y) in a new thread.

Definition at line 146 of file tbb_thread.h.

146  {
147  typedef internal::thread_closure_2<F,X,Y> closure_type;
148  internal_start(closure_type::start_routine, new closure_type(f,x,y));
149  }
void __TBB_EXPORTED_METHOD internal_start(__TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine), void *closure)
Definition: tbb_thread.cpp:94

◆ tbb_thread_v3() [6/6]

tbb::internal::tbb_thread_v3::tbb_thread_v3 ( tbb_thread_v3 &&  x)
inline

Definition at line 152 of file tbb_thread.h.

153  : my_handle(x.my_handle)
154 #if _WIN32||_WIN64
155  , my_thread_id(x.my_thread_id)
156 #endif
157  {
158  x.internal_wipe();
159  }
native_handle_type my_handle
Definition: tbb_thread.h:196

◆ ~tbb_thread_v3()

tbb::internal::tbb_thread_v3::~tbb_thread_v3 ( )
inline

Definition at line 180 of file tbb_thread.h.

References __TBB_NOEXCEPT, and tbb::this_tbb_thread::get_id().

180 {if( joinable() ) detach();}
void __TBB_EXPORTED_METHOD detach()
When detach() returns, *this no longer represents the possibly continuing thread of execution...
Definition: tbb_thread.cpp:78
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:175
Here is the call graph for this function:

Member Function Documentation

◆ detach()

void tbb::internal::tbb_thread_v3::detach ( )

When detach() returns, *this no longer represents the possibly continuing thread of execution.

Definition at line 78 of file tbb_thread.cpp.

References tbb::internal::handle_perror(), tbb::internal::handle_win_error(), joinable(), and my_handle.

Referenced by tbb::internal::move_v3().

78  {
79  if (!joinable())
80  handle_perror( EINVAL, "tbb_thread::detach" ); // Invalid argument
81 #if _WIN32||_WIN64
82  BOOL status = CloseHandle( my_handle );
83  if ( status == 0 )
84  handle_win_error( GetLastError() );
85  my_thread_id = 0;
86 #else
87  int status = pthread_detach( my_handle );
88  if( status )
89  handle_perror( status, "pthread_detach" );
90 #endif // _WIN32||_WIN64
91  my_handle = 0;
92 }
void handle_win_error(int error_code)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info...
native_handle_type my_handle
Definition: tbb_thread.h:196
void __TBB_EXPORTED_FUNC handle_perror(int error_code, const char *aux_info)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info...
Definition: tbb_misc.cpp:78
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_id()

tbb_thread_v3::id tbb::internal::tbb_thread_v3::get_id ( ) const
inline

Definition at line 259 of file tbb_thread.h.

References __TBB_EXPORTED_FUNC, id, tbb::internal::move_v3(), tbb::internal::thread_get_id_v3(), tbb::internal::thread_sleep_v3(), and tbb::internal::thread_yield_v3().

Referenced by join().

259  {
260 #if _WIN32||_WIN64
261  return id(my_thread_id);
262 #else
263  return id(my_handle);
264 #endif // _WIN32||_WIN64
265  }
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id id
native_handle_type my_handle
Definition: tbb_thread.h:196
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hardware_concurrency()

unsigned tbb::internal::tbb_thread_v3::hardware_concurrency ( )
static

The number of hardware thread contexts.

Before TBB 3.0 U4 this methods returned the number of logical CPU in the system. Currently on Windows, Linux and FreeBSD it returns the number of logical CPUs available to the current process in accordance with its affinity mask.

NOTE: The return value of this method never changes after its first invocation. This means that changes in the process affinity mask that took place after this method was first invoked will not affect the number of worker threads in the TBB worker threads pool.

Definition at line 139 of file tbb_thread.cpp.

References tbb::internal::governor::default_num_threads().

139  {
141 }
static unsigned default_num_threads()
Definition: governor.h:85
Here is the call graph for this function:

◆ internal_move()

void tbb::internal::tbb_thread_v3::internal_move ( tbb_thread_v3 x)
inlineprivate

Definition at line 207 of file tbb_thread.h.

References __TBB_EXPORTED_FUNC, __TBB_EXPORTED_METHOD, __TBB_NATIVE_THREAD_ROUTINE_PTR, __TBB_NOEXCEPT, internal_wipe(), tbb::internal::move_v3(), my_handle, and tbb::swap().

207  {
208  if (joinable()) detach();
209  my_handle = x.my_handle;
210 #if _WIN32||_WIN64
211  my_thread_id = x.my_thread_id;
212 #endif // _WIN32||_WIN64
213  x.internal_wipe();
214  }
void __TBB_EXPORTED_METHOD detach()
When detach() returns, *this no longer represents the possibly continuing thread of execution...
Definition: tbb_thread.cpp:78
native_handle_type my_handle
Definition: tbb_thread.h:196
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:175
Here is the call graph for this function:

◆ internal_start()

void tbb::internal::tbb_thread_v3::internal_start ( __TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine)  ,
void closure 
)
private

Runs start_routine(closure) on another thread and sets my_handle to the handle of the created thread.

Definition at line 94 of file tbb_thread.cpp.

References tbb::interface9::global_control::active_value(), tbb::internal::handle_perror(), my_handle, and tbb::interface9::global_control::thread_stack_size.

95  {
96 #if _WIN32||_WIN64
97 #if __TBB_WIN8UI_SUPPORT
98  std::thread* thread_tmp=new std::thread(start_routine, closure);
99  my_handle = thread_tmp->native_handle();
100 // TODO: to find out the way to find thread_id without GetThreadId and other
101 // desktop functions.
102 // Now tbb_thread does have its own thread_id that stores std::thread object
103  my_thread_id = (size_t)thread_tmp;
104 #else
105  unsigned thread_id;
106  // The return type of _beginthreadex is "uintptr_t" on new MS compilers,
107  // and 'unsigned long' on old MS compilers. uintptr_t works for both.
108  uintptr_t status = _beginthreadex( NULL, (unsigned)global_control::active_value(global_control::thread_stack_size),
109  start_routine, closure, 0, &thread_id );
110  if( status==0 )
111  handle_perror(errno,"__beginthreadex");
112  else {
113  my_handle = (HANDLE)status;
114  my_thread_id = thread_id;
115  }
116 #endif
117 #else
118  pthread_t thread_handle;
119  int status;
120  pthread_attr_t stack_size;
121  status = pthread_attr_init( &stack_size );
122  if( status )
123  handle_perror( status, "pthread_attr_init" );
124  status = pthread_attr_setstacksize( &stack_size, global_control::active_value(global_control::thread_stack_size) );
125  if( status )
126  handle_perror( status, "pthread_attr_setstacksize" );
127 
128  status = pthread_create( &thread_handle, &stack_size, start_routine, closure );
129  if( status )
130  handle_perror( status, "pthread_create" );
131  status = pthread_attr_destroy( &stack_size );
132  if( status )
133  handle_perror( status, "pthread_attr_destroy" );
134 
136 #endif // _WIN32||_WIN64
137 }
static size_t active_value(parameter p)
thread_monitor::handle_type thread_handle
native_handle_type my_handle
Definition: tbb_thread.h:196
void __TBB_EXPORTED_FUNC handle_perror(int error_code, const char *aux_info)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info...
Definition: tbb_misc.cpp:78
Here is the call graph for this function:

◆ internal_wipe()

void tbb::internal::tbb_thread_v3::internal_wipe ( )
inlineprivate

Definition at line 201 of file tbb_thread.h.

Referenced by internal_move().

201  {
202  my_handle = 0;
203 #if _WIN32||_WIN64
204  my_thread_id = 0;
205 #endif
206  }
native_handle_type my_handle
Definition: tbb_thread.h:196
Here is the caller graph for this function:

◆ join()

void tbb::internal::tbb_thread_v3::join ( )

The completion of the thread represented by *this happens before join() returns.

Definition at line 50 of file tbb_thread.cpp.

References get_id(), tbb::this_tbb_thread::get_id(), tbb::internal::handle_perror(), tbb::internal::handle_win_error(), joinable(), and my_handle.

51 {
52  if (!joinable())
53  handle_perror( EINVAL, "tbb_thread::join" ); // Invalid argument
55  handle_perror( EDEADLK, "tbb_thread::join" ); // Resource deadlock avoided
56 #if _WIN32||_WIN64
57 #if __TBB_WIN8UI_SUPPORT
58  std::thread* thread_tmp=(std::thread*)my_thread_id;
59  thread_tmp->join();
60  delete thread_tmp;
61 #else // __TBB_WIN8UI_SUPPORT
62  DWORD status = WaitForSingleObjectEx( my_handle, INFINITE, FALSE );
63  if ( status == WAIT_FAILED )
64  handle_win_error( GetLastError() );
65  BOOL close_stat = CloseHandle( my_handle );
66  if ( close_stat == 0 )
67  handle_win_error( GetLastError() );
68  my_thread_id = 0;
69 #endif // __TBB_WIN8UI_SUPPORT
70 #else
71  int status = pthread_join( my_handle, NULL );
72  if( status )
73  handle_perror( status, "pthread_join" );
74 #endif // _WIN32||_WIN64
75  my_handle = 0;
76 }
void handle_win_error(int error_code)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info...
tbb_thread::id get_id()
Definition: tbb_thread.h:321
native_handle_type my_handle
Definition: tbb_thread.h:196
id get_id() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:259
void __TBB_EXPORTED_FUNC handle_perror(int error_code, const char *aux_info)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info...
Definition: tbb_misc.cpp:78
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:175
Here is the call graph for this function:

◆ joinable()

bool tbb::internal::tbb_thread_v3::joinable ( ) const
inline

Definition at line 175 of file tbb_thread.h.

References __TBB_EXPORTED_METHOD.

Referenced by detach(), join(), and tbb::internal::move_v3().

175 {return my_handle!=0; }
native_handle_type my_handle
Definition: tbb_thread.h:196
Here is the caller graph for this function:

◆ native_handle()

native_handle_type tbb::internal::tbb_thread_v3::native_handle ( )
inline

Definition at line 182 of file tbb_thread.h.

References __TBB_EXPORTED_FUNC, and __TBB_NOEXCEPT.

182 { return my_handle; }
native_handle_type my_handle
Definition: tbb_thread.h:196

◆ operator=() [1/2]

tbb_thread_v3& tbb::internal::tbb_thread_v3::operator= ( tbb_thread_v3 &&  x)
inline

Definition at line 160 of file tbb_thread.h.

160  {
161  internal_move(x);
162  return *this;
163  }
void internal_move(tbb_thread_v3 &x) __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:207

◆ operator=() [2/2]

tbb_thread_v3& tbb::internal::tbb_thread_v3::operator= ( const tbb_thread_v3 x)
private

◆ swap()

void tbb::internal::tbb_thread_v3::swap ( tbb_thread_v3 t)
inline

Definition at line 174 of file tbb_thread.h.

References tbb::swap().

174 {tbb::swap( *this, t );}
void swap(concurrent_hash_map< Key, T, HashCompare, A > &a, concurrent_hash_map< Key, T, HashCompare, A > &b)
Here is the call graph for this function:

Friends And Related Function Documentation

◆ move_v3

void __TBB_EXPORTED_FUNC move_v3 ( tbb_thread_v3 t1,
tbb_thread_v3 t2 
)
friend

Definition at line 151 of file tbb_thread.cpp.

152 {
153  if (t1.joinable())
154  t1.detach();
155  t1.my_handle = t2.my_handle;
156  t2.my_handle = 0;
157 #if _WIN32||_WIN64
158  t1.my_thread_id = t2.my_thread_id;
159  t2.my_thread_id = 0;
160 #endif // _WIN32||_WIN64
161 }

◆ tbb::swap

void tbb::swap ( tbb_thread_v3 t1,
tbb_thread_v3 t2 
)
friend

Member Data Documentation

◆ my_handle

native_handle_type tbb::internal::tbb_thread_v3::my_handle
private

Definition at line 196 of file tbb_thread.h.

Referenced by detach(), internal_move(), internal_start(), join(), and tbb::internal::move_v3().


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

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.