[Insight-developers] itkSemaphore on Mac

Joshua Cates cates at sci . utah . edu
Thu, 28 Aug 2003 15:47:43 -0600 (MDT)


Thanks Yarden.  I'll try this approach.

Josh.

On Thu, 28 Aug 2003, Yarden Livnat wrote:

> true, sem_init is not implemented on the mac (last I checked).
> here is code from SCIRun which implements sem_init: (note, it's not 
> perfect and I had questions to which I did not have answer when I 
> implemented it - however, it works.
> 
> 	Yarden
> 
> 
> sem_t* SEM_INIT( const char *name, int shared, unsigned int val )
> {
>    static int num_inits = 0;
>    static int num_fails = 0;
> 
>    num_inits++;
>    // what is the maximum length ?
>    char local[40];
>    if ( strlen(name) > 25 ) {
>      strncpy( local, name, 25 );
>      local[25] = 0;
>      name = local;
>    }
>    sem_t *sem = sem_open( name, O_CREAT, shared, val );
>    if ( sem == (sem_t *)SEM_FAILED) {
>      num_fails++;
>      // why does it fail the first time ?
>      //perror("failed:");
>      sem_unlink(name);
>      sem = sem_open( name, O_CREAT , shared, val );
>      if ( sem == (sem_t *)SEM_FAILED )
>        {
> 	num_fails++;
> 	char errmsg[1024];
> 	printf("error: num_inits %d, num_fails %d\n", num_inits, num_fails);
> 	sprintf( errmsg,
> 		 "Thread_pthreads.cc: Mac OSX SEM_INIT: sem_open failed (twice): %s",
> 		 name );
> 	perror( errmsg );
>        } else {
> 	num_inits++;
>        }
>    } else {
>      num_inits++;
>    }
> 
>    return sem;
> }
> 
> On Aug 28, 2003, at 2:06 PM, Brad King wrote:
> 
> > Josh,
> >
> > I've found the reason for the itkSemaphoreTest failure on the Mac.  I
> > modified the code that throws an exception after sem_init fails to 
> > print
> > the strerror(errno) in the string.  The test now fails and produces 
> > this
> > line in the output:
> >
> > Description: itk::ERROR: Semaphore(0x39c28e0): sem_init call failed:
> > Function not implemented
> >
> > Anyone have any ideas about what to do now?  Does Mac have another
> > semaphore implementation?
> >
> > -Brad
> >
> >
> > _______________________________________________
> > Insight-developers mailing list
> > Insight-developers at itk . org
> > http://www . itk . org/mailman/listinfo/insight-developers
> 
>