[cpp-threads] Re: Comments on N2094 MT API proposal

Anthony Williams anthony at justsoftwaresolutions.co.uk
Fri Sep 15 15:20:39 BST 2006


"Peter Dimov" <pdimov at mmltd.net> writes:

> To: C++ extensions mailing list
> Message c++std-ext-7974
>
> Howard Hinnant wrote in message c++std-ext-7971:
>
>> On Sep 15, 2006, at 4:21 AM, Anthony Williams wrote:
>
> [...]
>
>>> void f(mutex& m)
>>> {
>>>     m.lock_sharable();
>>>     std::thread_util::sleep(100); // or some other time-consuming op
>>>     while(!m.try_unlock_sharable_and_lock())
>>>     {
>>>         std::thread_util::yield();
>>>     }
>>> }
>>>
>>> If both threads get the sharable lock, neither will be able to
>>> upgrade to a full lock, so they will both loop forever.
>
> All of these are broken even if deadlock never occurs. yield() doesn't yield
> to lower priority threads. I'm still not convinced that we need to provide
> "yield". (I don't oppose try_unlock_sharable_and_lock.)

You can substitute an appropriate call to sleep(), or just about anything in
place of yield(), and deadlock could still occur.

Why are you presuming that yield() wouldn't yield to lower priority threads?
Surely that would be one of the reasons to call it?

Anthony
-- 
Anthony Williams
Software Developer
Just Software Solutions Ltd
http://www.justsoftwaresolutions.co.uk



More information about the cpp-threads mailing list