[Insight-developers] Mac Semaphores (Was: Failing tests and compile errors after your check in)

Bradley Lowekamp blowekamp at mail.nih.gov
Fri Feb 18 14:16:10 EST 2011


If my understanding is correct we implementing ITK semaphores with cross process POSIX semaphores. This just doesn't seem right to me.

If we do need the semaphore class I like Dans suggestion of using a pthread conditional variable internally. I would be curious what the performance difference is.

B


On Feb 18, 2011, at 1:49 PM, Sean McBride wrote:

> On Fri, 18 Feb 2011 11:59:07 -0600, Daniel Blezek said:
> 
>> POSIX semaphores are not fully supported on the Mac.
> 
> Mac OS X complies with POSIX 1003.1 and UNIX03.  The sem* functions are
> optional according to that standard.  A pity they didn't implement them. :(
> 
>> I don't know why this
>> works in the 64-bit version...
>> 
>> We are using sem_destroy to destroy our semaphores.  On the 32-bit Mac, I
>> get this return value (perror()):
>> 
>> 536: sem_destroy: Function not implemented
>> 
>> Why this linked and run, I'll never know...  Looks like I need to add some
>> APPLE specific code.  I suspect this will fix the problem on the Sun.
> 
> Apparently the standard at one point required failing stub functions,
> which is presumably why it links & runs.
> 
> The correct test for the sem functions is:
> 
> #if _POSIX_SEMAPHORES && (_POSIX_SEMAPHORES - 200112L) >= 0
> 
> See here for more:
> <http://lists.apple.com/archives/unix-porting/2009/May/msg00004.html>
> 
> An alternative is to use System V semaphores: semget().
> 
>> We also have a race-condition in our Semaphore code.  On the Mac, the
>> semaphores need unique names.  We generate this using the time() function,
>> but it has a one second resolution.  Thus if two semaphores are created
>> within 1 second, they will collide.  Not very nice.
> 
> mach_absolute_time() gives the best precision, but it's not portable. 
> Or maybe use uuid_generate()?
> 
> -- 
> ____________________________________________________________
> Sean McBride, B. Eng                 sean at rogue-research.com
> Rogue Research                        www.rogue-research.com 
> Mac Software Developer              Montréal, Québec, Canada
> 
> 

========================================================
Bradley Lowekamp  
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110218/5e5c081d/attachment.htm>


More information about the Insight-developers mailing list