Home ⌂Doc Index ◂Up ▴
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 122 of file tbb_thread.h.

Member Typedef Documentation

◆ native_handle_type

Definition at line 134 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 139 of file tbb_thread.h.

139  : my_handle(0)
140 #if _WIN32||_WIN64
141  , my_thread_id(0)
142 #endif // _WIN32||_WIN64
143  {}
native_handle_type my_handle
Definition: tbb_thread.h:206

◆ 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 146 of file tbb_thread.h.

146  {
147  typedef internal::thread_closure_0<F> closure_type;
148  internal_start(closure_type::start_routine, new closure_type(f));
149  }
void __TBB_EXPORTED_METHOD internal_start(__TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine), void *closure)
Definition: tbb_thread.cpp:90

References internal_start().

Here is the call graph for this function:

◆ 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 151 of file tbb_thread.h.

151  {
152  typedef internal::thread_closure_1<F,X> closure_type;
153  internal_start(closure_type::start_routine, new closure_type(f,x));
154  }
void __TBB_EXPORTED_METHOD internal_start(__TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine), void *closure)
Definition: tbb_thread.cpp:90

References internal_start().

Here is the call graph for this function:

◆ 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 156 of file tbb_thread.h.

156  {
157  typedef internal::thread_closure_2<F,X,Y> closure_type;
158  internal_start(closure_type::start_routine, new closure_type(f,x,y));
159  }
void __TBB_EXPORTED_METHOD internal_start(__TBB_NATIVE_THREAD_ROUTINE_PTR(start_routine), void *closure)
Definition: tbb_thread.cpp:90

References internal_start().

Here is the call graph for this function:

◆ tbb_thread_v3() [6/6]

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

Definition at line 162 of file tbb_thread.h.

163  : my_handle(x.my_handle)
164 #if _WIN32||_WIN64
165  , my_thread_id(x.my_thread_id)
166 #endif
167  {
168  x.internal_wipe();
169  }
native_handle_type my_handle
Definition: tbb_thread.h:206

◆ ~tbb_thread_v3()

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

Definition at line 190 of file tbb_thread.h.

190 {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:74
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:185

References detach(), and joinable().

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 74 of file tbb_thread.cpp.

74  {
75  if (!joinable())
76  handle_perror( EINVAL, "tbb_thread::detach" ); // Invalid argument
77 #if _WIN32||_WIN64
78  BOOL status = CloseHandle( my_handle );
79  if ( status == 0 )
80  handle_win_error( GetLastError() );
81  my_thread_id = 0;
82 #else
83  int status = pthread_detach( my_handle );
84  if( status )
85  handle_perror( status, "pthread_detach" );
86 #endif // _WIN32||_WIN64
87  my_handle = 0;
88 }
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:87
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:185
native_handle_type my_handle
Definition: tbb_thread.h:206
void handle_win_error(int error_code)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info.

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

Referenced by internal_move(), tbb::internal::move_v3(), and ~tbb_thread_v3().

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 269 of file tbb_thread.h.

269  {
270 #if _WIN32||_WIN64
271  return id(my_thread_id);
272 #else
273  return id(my_handle);
274 #endif // _WIN32||_WIN64
275  }
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:206

References id, and my_handle.

Referenced by join().

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 135 of file tbb_thread.cpp.

135  {
137 }
static unsigned default_num_threads()
Definition: governor.h:84

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

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 217 of file tbb_thread.h.

217  {
218  if (joinable()) detach();
219  my_handle = x.my_handle;
220 #if _WIN32||_WIN64
221  my_thread_id = x.my_thread_id;
222 #endif // _WIN32||_WIN64
223  x.internal_wipe();
224  }
void __TBB_EXPORTED_METHOD detach()
When detach() returns, *this no longer represents the possibly continuing thread of execution.
Definition: tbb_thread.cpp:74
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:185
native_handle_type my_handle
Definition: tbb_thread.h:206

References detach(), joinable(), and my_handle.

Referenced by operator=().

Here is the call graph for this function:
Here is the caller 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 90 of file tbb_thread.cpp.

91  {
92 #if _WIN32||_WIN64
93 #if __TBB_WIN8UI_SUPPORT
94  std::thread* thread_tmp=new std::thread(start_routine, closure);
95  my_handle = thread_tmp->native_handle();
96 // TODO: to find out the way to find thread_id without GetThreadId and other
97 // desktop functions.
98 // Now tbb_thread does have its own thread_id that stores std::thread object
99  my_thread_id = (size_t)thread_tmp;
100 #else
101  unsigned thread_id;
102  // The return type of _beginthreadex is "uintptr_t" on new MS compilers,
103  // and 'unsigned long' on old MS compilers. uintptr_t works for both.
104  uintptr_t status = _beginthreadex( NULL, (unsigned)global_control::active_value(global_control::thread_stack_size),
105  start_routine, closure, 0, &thread_id );
106  if( status==0 )
107  handle_perror(errno,"__beginthreadex");
108  else {
109  my_handle = (HANDLE)status;
110  my_thread_id = thread_id;
111  }
112 #endif
113 #else
114  pthread_t thread_handle;
115  int status;
116  pthread_attr_t stack_size;
117  status = pthread_attr_init( &stack_size );
118  if( status )
119  handle_perror( status, "pthread_attr_init" );
120  status = pthread_attr_setstacksize( &stack_size, global_control::active_value(global_control::thread_stack_size) );
121  if( status )
122  handle_perror( status, "pthread_attr_setstacksize" );
123 
124  status = pthread_create( &thread_handle, &stack_size, start_routine, closure );
125  if( status )
126  handle_perror( status, "pthread_create" );
127  status = pthread_attr_destroy( &stack_size );
128  if( status )
129  handle_perror( status, "pthread_attr_destroy" );
130 
132 #endif // _WIN32||_WIN64
133 }
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:87
static size_t active_value(parameter p)
thread_monitor::handle_type thread_handle
native_handle_type my_handle
Definition: tbb_thread.h:206

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

Referenced by tbb_thread_v3().

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

◆ internal_wipe()

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

Definition at line 211 of file tbb_thread.h.

211  {
212  my_handle = 0;
213 #if _WIN32||_WIN64
214  my_thread_id = 0;
215 #endif
216  }
native_handle_type my_handle
Definition: tbb_thread.h:206

References my_handle.

◆ join()

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

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

Definition at line 46 of file tbb_thread.cpp.

47 {
48  if (!joinable())
49  handle_perror( EINVAL, "tbb_thread::join" ); // Invalid argument
51  handle_perror( EDEADLK, "tbb_thread::join" ); // Resource deadlock avoided
52 #if _WIN32||_WIN64
53 #if __TBB_WIN8UI_SUPPORT
54  std::thread* thread_tmp=(std::thread*)my_thread_id;
55  thread_tmp->join();
56  delete thread_tmp;
57 #else // __TBB_WIN8UI_SUPPORT
58  DWORD status = WaitForSingleObjectEx( my_handle, INFINITE, FALSE );
59  if ( status == WAIT_FAILED )
60  handle_win_error( GetLastError() );
61  BOOL close_stat = CloseHandle( my_handle );
62  if ( close_stat == 0 )
63  handle_win_error( GetLastError() );
64  my_thread_id = 0;
65 #endif // __TBB_WIN8UI_SUPPORT
66 #else
67  int status = pthread_join( my_handle, NULL );
68  if( status )
69  handle_perror( status, "pthread_join" );
70 #endif // _WIN32||_WIN64
71  my_handle = 0;
72 }
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:87
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:185
__TBB_DEPRECATED_IN_VERBOSE_MODE tbb_thread::id get_id()
Definition: tbb_thread.h:331
native_handle_type my_handle
Definition: tbb_thread.h:206
void handle_win_error(int error_code)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info.
id get_id() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:269

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

Here is the call graph for this function:

◆ joinable()

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

Definition at line 185 of file tbb_thread.h.

185 {return my_handle!=0; }
native_handle_type my_handle
Definition: tbb_thread.h:206

References my_handle.

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

Here is the caller graph for this function:

◆ native_handle()

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

Definition at line 192 of file tbb_thread.h.

192 { return my_handle; }
native_handle_type my_handle
Definition: tbb_thread.h:206

References my_handle.

◆ operator=() [1/2]

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

Definition at line 170 of file tbb_thread.h.

170  {
171  internal_move(x);
172  return *this;
173  }
void internal_move(tbb_thread_v3 &x) __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:217

References internal_move().

Here is the call graph for this function:

◆ 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 184 of file tbb_thread.h.

184 {tbb::swap( *this, t );}
void swap(concurrent_hash_map< Key, T, HashCompare, A > &a, concurrent_hash_map< Key, T, HashCompare, A > &b)

References tbb::swap().

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 147 of file tbb_thread.cpp.

148 {
149  if (t1.joinable())
150  t1.detach();
151  t1.my_handle = t2.my_handle;
152  t2.my_handle = 0;
153 #if _WIN32||_WIN64
154  t1.my_thread_id = t2.my_thread_id;
155  t2.my_thread_id = 0;
156 #endif // _WIN32||_WIN64
157 }

◆ 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

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

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.