|
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