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

Robert Watson robert at fledge.watson.org
Sat Oct 31 02:56:14 PDT 2009


On Fri, 30 Oct 2009, Kevin Van Vechten wrote:

>> #else /* !HAVE_MACH */
>> static void
>> _dispatch_posix_semaphore_create(sem_t *s4)
>> {
>> 	if (*s4) return;
>> 	ret = sem_init(s4, 0, 0); // XXX race condition for assignment to s4
>> }
>> #endif /* HAVE_MACH */
>
> 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.

Especially given that the size of sem_t appears to exceed the maximum size of 
types that can be operated on using atomic instructions on some systems. I 
agree that I got the semantics off there in the port.  However, eliminating 
this optimization may not be a big deal: pthread semaphores will already 
likely have similarly optimized behavior on most systems, and if not, can grow 
them. :-)

Robert N M Watson
Computer Laboratory
University of Cambridge


More information about the libdispatch-dev mailing list