[Insight-developers] Mac Semaphore Implementation

Hans Johnson hans-johnson at uiowa.edu
Fri Sep 2 16:45:28 EDT 2005


All,

I was having a strange failure when using the itkSemaphore on Mac.  It is
used extensively in brains2, and after several days of continuous regression
testing, eventually the itkSemaphore creation would start producing
consistent errors.  A reboot of the computer would immediately resolve the
problem for a few more days.

The problem presented it self on the dashboard with 100% test passing for a
day or two, then 1/2 way through one of the continuous builds, all remaining
test, and all future tests would fail.

I believe that the problem is that on Mac named semaphores are used that
create a virtual file in the shared memory space.  These files are created
for each named instance of the semaphore, but the destructor code was never
removing the files.   Eventually the shared memory would fill up with these
virtual files.

I have made modifications to the itkSemaphore.cxx program, and have been
continuously generating itkSemaphores for about 6 hours now.  I've attached
a patch that I believe has resolved my troubles.  Would the ITK semaphore
experts please review the changes I propose and let me know if I've done
this correctly?  I can commit it as soon as the code freeze is lifted.


Hans





Index: itkSemaphore.cxx
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/Common/itkSemaphore.cxx,v
retrieving revision 1.12
diff -r1.12 itkSemaphore.cxx
315a316,326
> #else //Still need to close semaphore and delete the file descriptor on
MacOSX, otherwise the shared memory space is eventually exhosted.
>   //Eventually (i.e. after several days of ITK regresssion testing) the
semaphore creation process was failing with errno=ENOSPC
>   //This implementation detail was taken from
http://developer.apple.com/macosx/multithreadedprogramming.html
>   if ( sem_close(this->m_Sema) !=0 )
>       {
>        itkExceptionMacro( << "sem_close call failed. " );
>       }
>   if ( sem_unlink(this->m_SemaphoreName.c_str()) !=0 )
>       {
>        itkExceptionMacro( << "sem_unlink call failed. " );
>       }




More information about the Insight-developers mailing list