|
Threads-Devel : |
From: Anthony Williams (anthony_at_[hidden])
Date: 2006-03-13 03:25:55
David Abrahams <dave_at_[hidden]> writes:
> Anthony Williams <anthony_at_[hidden]> writes:
>
>> Hi all,
>>
>> I have now reimplemented condition variables for win32. After
>> careful thought, I decided that my previous implementation was
>> subject to possible race conditions, so I started again from
>> scratch.
>>
>> The new implementation of condition variables has templated wait
>> functions, so any type of lock can be used when waiting.
>>
>> The basic idea is really simple. When a thread waits on the
>> condition variable, it is added to the back of the list of
>> waiters. When a thread calls notify_one, it wakes the head of the
>> list; if a thread calls notify_all, it wakes all list members.
>
> Fantastic work, Anthony! This is really encouraging; we could be
> free of the old license code and crufty implementation by 1.35!
That's what I'm aiming for.
> I suppose there must be a mutex or critical section under the covers
> to protect the list?
Yes.
> Does it make sense, someday in the future, to
> consider a lock-free implementation of the list, as an optimization?
That would make sense. At the present time I'm not sure how to implement that
without changing the implementation --- I need a doubly-linked list, so
removing an element means accessing 4 pointers (find next + previous, and
update their previous and next pointers respectively).
Anthony
-- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk