Mixing C++11 std::thread and C system threads (ie pthreads)
C++11 threads may or may not have a member function named native_handle()
; it's implementation-defined whether this exists. If it exists, it returns an object of type native_handle_type
; it's implementation-defined what an object of this type can be used for. So read your documentation.
The C++ standard doesn't specify how C++ threads interact with any other thread library, but in general I would expect a C++ implementation to use the underlying system thread library, so your usage should be safe.
Being able to use a third-party library that uses the system thread library locking primitives is such a common use case that it should be expected to work (otherwise C++ threading support would be almost useless in lots of real-world situations). As Pete points out, anything involving thread handles/ids can be more tricky (but shouldn't be required from reading your question).
It depends on what the library is actually doing. Using pthreads
for mutices and such shouldn't be a problem. However in case the library actually tries to manage the threads using functions like pthread_join
, it will likely lead to problems. It might still work on systems where pthread
is the standard (unix and such), since std::thread
can be implemented as a very thin wrapper around pthreads
, but that would obviously be very implementation dependent and not something I would count on working even for future versions of the same compiler. Similar Arguments can be made for usage of CreateThread
.