[libdispatch-dev] [PATCH 09/17] portability

Paolo Bonzini bonzini at gnu.org
Fri Oct 30 12:22:31 PDT 2009


On 10/30/2009 08:21 PM, Kevin Van Vechten wrote:
>
>
> On Oct 30, 2009, at 11:18 AM, Paolo Bonzini wrote:
>
>> On 10/30/2009 07:14 PM, Kevin Van Vechten wrote:
>>> Based on the above discussion it seems like we may need to make
>>> dispatch_semaphore_t be a thinner wrapper around OS semaphores
>>> on platforms where the semaphore's handle cannot be atomically
>>> exchanged — i.e. we may need to forgo the optimization of lazily
>>> allocating the OS semaphore.
>>
>> Yep.  OTOH, on Linux you'd probably want to use futexes which
>> perform the same optimization (if you don't do the system call, the
>> futex is just an "int").  So long-term some of these wrappers would
>> move into src/shims.
>>
>> Let's just leave aside this fix.
>
> To be clear, the posix semaphore implementation is currently broken
> due to this race condition.

Yes, but not on BSD systems where sem_t can be assigned atomically.

For Linux the solution is simply not to use sem_t.  I'll get to it.

Paolo



More information about the libdispatch-dev mailing list