I am writing a multithreaded C++ program and wish to use a multithreaded C library.
This library expects me to use the native system methods to create it some worker threads and pass control to its run() function using code such as this:
void system_specific_thread_init();
#ifdef _WIN32
DWORD WINAPI system_specific_thread_run( LPVOID unused )
{
library_run();
return 0;
}
void system_specific_thread_init()
{
Createthread(NULL, 0, system_specific_thread_run, NULL, 0, NULL);
}
#else
void* system_specific_thread_run(void *unused)
{
library_run();
return NULL;
}
void system_specific_thread_init()
{
pthread_t id;
pthread_create(&id, NULL, system_specific_thread_run, NULL);
}
#endif
system_specific_thread_init();
after which it will use the relevant native system mutex methods to other native system threads to call its functions while getting on with is own work.
However, I am using the C++11 <thread>
library to create and manage all my threads. I wish to create the worker thread(s) with std::thread(library_run)
and call the library functions from other such threads.
Is it safe to do this, or will the DS9K cause demons to fly out of my nose?