Boost logo

Boost Users :

Subject: Re: [Boost-users] initialization of boost::thread::id object
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2010-06-09 03:25:09


Boost lzw <boostlzw_at_[hidden]> writes:

> Thanks a lot for the answer. In fact, I am trying to associate data
> (std::vector<int> and Widget objects) with a boost::mutex by wrapping its
> interface [ lock(), try_lock() and unlock() ] as follows:
>  
> class Widget { ... }; // data to be associated with
>  
> class MyData {
> public:
>    MyData(std::vector<int>& v) : v_(v), w_(new Widget) { }
>
>    ~MyData() {
>         m_.~mutex();

Do not call destructors manually. This will lead to undefined behaviour.

>       delete w_;
>  }

>  void unlock() {
>        id_ = 0;  // reset it, does not compile

id_ = boost::thread::id();

>        m_.unlock();
>   }

HTH,

Anthony

-- 
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++0x thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

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