boost::thread - Checking that an object is called from the right thread

I've got an object that should only be called from the thread that instantiated, and I'd like the object to check that. Using pthreads I've checked this with pthread_self, but now I'm moving to boost threads, my code looks like this: class MyClass { boost::thread instantiating_thread; public: void doSomething() { // Verify that we have been called from the right thread assert(boost::thread() == instantiating_thread) // Actually do something... } }; Is this alright? The boost::threads documentation has this to say about the boost::thread() default constructor: 1. thread(); Effects: Constructs a thread object representing the current thread of execution. Postconditions: *this is non-joinable. Notes: Danger:*this is valid only within the current thread. (http://www.boost.org/doc/html/thread.html) If *this is not valid from another thread, as the documentation states, then my assert above is broken, right? Regards, Thomas Søndergaard
participants (1)
-
Thomas Sondergaard