Boost logo

Boost Users :

Subject: Re: [Boost-users] [rerepost][threads] recursive shared_mutex
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-05-06 13:10:53


Filip Konvicka:
>> 2. The basic technique is
>>
>> http://www.decadentplace.org.uk/pipermail/cpp-threads/2006-August/001082.html
>> (except that the store_release to count_ is not necessary, it's under a
>> lock, count_ = 1 is sufficient)
>>
>> but, as I point out, it requires an atomic thread ID type.
>
> One could probably use boost::detail::spinlock_pool for that.

It would probably be too slow. On platforms where the native "thread ID" is
not an atomic type, one might use (in "C++0x pseudocode")

unsigned get_thread_id()
{
    static thread_local unsigned t_tid;
    static std::atomic<unsigned> s_tid;

    if( t_tid == 0 )
    {
        t_tid = ++s_tid;
    }

    return t_tid;
}

> Peter, thanks for providing this :-) BTW, do you plan to release spinlocks
> as a regular Boost library?

I'm not ready to do that at the moment.


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