For purposes of thread local cleanup I need to create an assertion that checks if the current thread was created via boost::thread. How can I can check if this was the case
You can't do this with a static assertion: That would mean you could detect it at compile time, and that's impossible.
Assuming you mean a runtime check though:
If you don't mix boost::thread
with other methods, then the problem just goes away. Any libraries that are creating threads should already be dealing with their own threads automatically (or per a shutdown function the API documents that you must call).
Otherwise you can keep, for example, a container of all pthread_t
s you create not using boost::thread
and check if the thread is in the container when shutting down. If it's not in the container then it was created using boost::thread
.
EDIT: Instead of trying to detect if it was created with boost::thread
, have you considered setting up your application so that the API callback can only occur in threads created with boost::thread
? This way you prevent the problem up front and eliminate the need for a check that, if it even exists, would be painful to implement.