문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top