Looking at the differences between the patch I submitted for sem.c and
the original code, I figured out why the original code for unnamed
semaphores was crashing my otherwise posix correct use of  semaphores.
The sem_init() function is returning the address of a new semaphore,
but this is not right. sem_init() initializes the semaphore *at* the
address pointed. To return the address of a new semaphore, sem_open()
is used.

Furthermore, from the man pages:
"Before   being   used,   an  unnamed  semaphore  must  be  initialized  using
              sem_init(3).  It can then be operated on using
sem_post(3)  and  sem_wait(3).
              When  the  semaphore is no longer required, and before
the memory in which it
              is  located  is  deallocated,  the  semaphore  should
be   destroyed   using
              sem_destroy(3)."

So in doubt, I go to the code in glibc, and find:


int
__new_sem_init (sem, pshared, value)
     sem_t *sem;
     int pshared;
     unsigned int value;
{
  /* Parameter sanity check.  */
  if (__builtin_expect (value > SEM_VALUE_MAX, 0))
    {
      __set_errno (EINVAL);
      return -1;
    }

  /* Map to the internal type.  */
  struct new_sem *isem = (struct new_sem *) sem;

  /* Use the values the user provided.  */
  isem->value = value;
#ifdef __ASSUME_PRIVATE_FUTEX
  isem->private = pshared ? 0 : FUTEX_PRIVATE_FLAG;
#else
  isem->private = pshared ? 0 : THREAD_GETMEM (THREAD_SELF,
                           header.private_futex);
#endif

  isem->nwaiters = 0;

  return 0;
}


Which means that the original code for semaphores in mingw-w64 is not
only incomplete (missing named semaphores) but broken.

The patch I submitted is missing a working sem_getvalue() function.
I'll prepare another patch with that function in working order and
some more changes on off-list suggestions by dw.


-- 
------------------------------------------------------------------------------------
Dr. Edscott Wilson Garcia
Applied Mathematics and Computing
Mexican Petroleum Institute

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to