Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 difference between <thread> get_id() and native_handle()

What is the difference between C++11 functions get_id() and native_handle()?

In the test program I created they return the same int value for their threads so I have no idea what the difference is.

I'm using GCC 4.8.1 on Windows.

like image 396
user3215354 Avatar asked May 15 '14 12:05

user3215354


1 Answers

From this reference:

get_id returns the id of the thread

and

native_handle returns the underlying implementation-defined thread handle

The thread identifier as returned by get_id should actually be a class (std::thread::id) and not a number or other platform specific handle.

The native_handle function returns just what its name implies, a native handle that can be used by the underlying operating systems thread functions. On Windows this is typically a HANDLE as returned by CreateThread, on POSIX platforms it's typically a pthread_t as initialized by pthread_create.

like image 119
Some programmer dude Avatar answered Sep 30 '22 01:09

Some programmer dude