Boost logo

Boost Users :

From: Thomas Sondergaard (ts_news1_at_[hidden])
Date: 2007-04-10 06:25:18


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net