Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2008-05-28 17:58:38

On May 28, 2008, at 3:02 PM, Peter Dimov wrote:

> Howard Hinnant:
>> I've used this (for example) in implementing recursive mutexes:
>> class recursive_mutex
>> {
>> unsigned state_;
>> std::thread::id id_;
> As already pointed out in the thread
> linked from #783, this requires thread::id atomicity, which is not
> guaranteed. I'm not sure whether instant reuse can also break this
> particular example, but it definitely breaks other uses of thread::id.

I probably made a mistake in posting code snippets instead of a
complete recursive_mutex. In the example I programmed, which was
actually a recurisve_timed_mutex instead of a recursive_mutex, there
were member mutex and condition_variables. The mutex was locked while
manipulating the internal state_ and id_, providing the required
atomicity, and preventing "instant reuse".

Since "not a thread" values do not exist (as far as I know) in
pthreads and Windows, I was trying to make the point that many people
probably haven't considered the use of such values in multithreading
programming in dealing with the id-reuse-problem. I believe this tool
will solve some, but not all, problems which "unique_id" addresses,
and with far less expense.


Boost list run by bdawes at, gregod at, cpdaniel at, john at