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_v3 & | operator= (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_v3 & | operator= (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

typedef pthread_t tbb::internal::tbb_thread_v3::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.

: my_handle(0)
#if _WIN32||_WIN64
, my_thread_id(0)
#endif // _WIN32||_WIN64
{}
tbb::internal::tbb_thread_v3::my_handle
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 | f | ) |

inline explicit

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

Definition at line 146 of file tbb_thread.h.

{
typedef internal::thread_closure_0<F> closure_type;
internal_start(closure_type::start_routine, new closure_type(f));
}
tbb::internal::tbb_thread_v3::internal_start
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 | f,
|  | X | x
| ) |  |

inline

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

Definition at line 151 of file tbb_thread.h.

{
typedef internal::thread_closure_1<F,X> closure_type;
internal_start(closure_type::start_routine, new closure_type(f,x));
}

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 | f,
|  | X | x,
|  | Y | y
| ) |  |

inline

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

Definition at line 156 of file tbb_thread.h.

{
typedef internal::thread_closure_2<F,X,Y> closure_type;
internal_start(closure_type::start_routine, new closure_type(f,x,y));
}

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.

: my_handle(x.my_handle)
#if _WIN32||_WIN64
, my_thread_id(x.my_thread_id)
#endif
{
x.internal_wipe();
}

## ~tbb_thread_v3()

tbb::internal::tbb_thread_v3::~tbb_thread_v3 | ( |  | ) |

inline

Definition at line 190 of file tbb_thread.h.

{if( joinable() ) detach();}
tbb::internal::tbb_thread_v3::joinable
bool joinable() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:185
tbb::internal::tbb_thread_v3::detach
void __TBB_EXPORTED_METHOD detach()
When detach() returns, *this no longer represents the possibly continuing thread of execution.
Definition: tbb_thread.cpp:74

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.

{
if (!joinable())
handle_perror( EINVAL, "tbb_thread::detach" ); // Invalid argument
#if _WIN32||_WIN64
BOOL status = CloseHandle( my_handle );
if ( status == 0 )
handle_win_error( GetLastError() );
my_thread_id = 0;
#else
int status = pthread_detach( my_handle );
if( status )
handle_perror( status, "pthread_detach" );
#endif // _WIN32||_WIN64
my_handle = 0;
}
tbb::internal::handle_perror
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
tbb::internal::handle_win_error
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(), 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.

{
#if _WIN32||_WIN64
return id(my_thread_id);
#else
return id(my_handle);
#endif // _WIN32||_WIN64
}
id
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
Definition: ittnotify_static.h:172

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.

{
return governor::default_num_threads();
}
tbb::internal::governor::default_num_threads
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 | ) |

inline private

Definition at line 217 of file tbb_thread.h.

{
if (joinable()) detach();
my_handle = x.my_handle;
#if _WIN32||_WIN64
my_thread_id = x.my_thread_id;
#endif // _WIN32||_WIN64
x.internal_wipe();
}

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.

{
#if _WIN32||_WIN64
#if __TBB_WIN8UI_SUPPORT
std::thread* thread_tmp=new std::thread(start_routine, closure);
my_handle = thread_tmp->native_handle();
// TODO: to find out the way to find thread_id without GetThreadId and other
// desktop functions.
// Now tbb_thread does have its own thread_id that stores std::thread object
my_thread_id = (size_t)thread_tmp;
#else
unsigned thread_id;
// The return type of _beginthreadex is "uintptr_t" on new MS compilers,
// and 'unsigned long' on old MS compilers. uintptr_t works for both.
uintptr_t status = _beginthreadex( NULL, (unsigned)global_control::active_value(global_control::thread_stack_size),
start_routine, closure, 0, &thread_id );
if( status==0 )
handle_perror(errno,"__beginthreadex");
else {
my_handle = (HANDLE)status;
my_thread_id = thread_id;
}
#endif
#else
pthread_t thread_handle;
int status;
pthread_attr_t stack_size;
status = pthread_attr_init( &stack_size );
if( status )
handle_perror( status, "pthread_attr_init" );
status = pthread_attr_setstacksize( &stack_size, global_control::active_value(global_control::thread_stack_size) );
if( status )
handle_perror( status, "pthread_attr_setstacksize" );
status = pthread_create( &thread_handle, &stack_size, start_routine, closure );
if( status )
handle_perror( status, "pthread_create" );
status = pthread_attr_destroy( &stack_size );
if( status )
handle_perror( status, "pthread_attr_destroy" );
my_handle = thread_handle;
#endif // _WIN32||_WIN64
}
tbb::internal::rml::thread_handle
thread_monitor::handle_type thread_handle
Definition: private_server.cpp:31
tbb::interface9::global_control::thread_stack_size
@ thread_stack_size
Definition: global_control.h:29
tbb::interface9::global_control::active_value
static size_t active_value(parameter p)
Definition: global_control.h:59

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 | ( |  | ) |

inline private

Definition at line 211 of file tbb_thread.h.

{
my_handle = 0;
#if _WIN32||_WIN64
my_thread_id = 0;
#endif
}

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.

{
if (!joinable())
handle_perror( EINVAL, "tbb_thread::join" ); // Invalid argument
if (this_tbb_thread::get_id() == get_id())
handle_perror( EDEADLK, "tbb_thread::join" ); // Resource deadlock avoided
#if _WIN32||_WIN64
#if __TBB_WIN8UI_SUPPORT
std::thread* thread_tmp=(std::thread*)my_thread_id;
thread_tmp->join();
delete thread_tmp;
#else // __TBB_WIN8UI_SUPPORT
DWORD status = WaitForSingleObjectEx( my_handle, INFINITE, FALSE );
if ( status == WAIT_FAILED )
handle_win_error( GetLastError() );
BOOL close_stat = CloseHandle( my_handle );
if ( close_stat == 0 )
handle_win_error( GetLastError() );
my_thread_id = 0;
#endif // __TBB_WIN8UI_SUPPORT
#else
int status = pthread_join( my_handle, NULL );
if( status )
handle_perror( status, "pthread_join" );
#endif // _WIN32||_WIN64
my_handle = 0;
}
tbb::this_tbb_thread::get_id
__TBB_DEPRECATED_IN_VERBOSE_MODE tbb_thread::id get_id()
Definition: tbb_thread.h:331
tbb::internal::tbb_thread_v3::get_id
id get_id() const __TBB_NOEXCEPT(true)
Definition: tbb_thread.h:269

References tbb::this_tbb_thread::get_id(), 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.

{return my_handle!=0; }

References my_handle.

Referenced by detach(), internal_move(), join(), 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.

{ return my_handle; }

References my_handle.

## operator=() [1/2]

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

private

## operator=() [2/2]

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

inline

Definition at line 170 of file tbb_thread.h.

{
internal_move(x);
return *this;
}
tbb::internal::tbb_thread_v3::internal_move
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:

## swap()

void tbb::internal::tbb_thread_v3::swap | ( | tbb_thread_v3 & | t | ) |

inline

Definition at line 184 of file tbb_thread.h.

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

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.

{
if (t1.joinable())
t1.detach();
t1.my_handle = t2.my_handle;
t2.my_handle = 0;
#if _WIN32||_WIN64
t1.my_thread_id = t2.my_thread_id;
t2.my_thread_id = 0;
#endif // _WIN32||_WIN64
}

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

Referenced by detach(), get_id(), internal_move(), internal_start(), internal_wipe(), join(), joinable(), and native_handle().

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

- tbb_thread.h
- tbb_thread.cpp

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.