Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try removing old semaphores before creating the new one, and to avoid name clashes
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 20 Mar 2017 14:30:41 +0000 (15:30 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 20 Mar 2017 14:35:57 +0000 (15:35 +0100)
src/xbt/xbt_os_thread.c

index 6208210..7bd87a6 100644 (file)
@@ -404,13 +404,15 @@ xbt_os_sem_t xbt_os_sem_init(unsigned int value)
 #else                           /* damn, no sem_init(). Reimplement it */
 
   xbt_os_mutex_acquire(next_sem_ID_lock);
-  res->name = bprintf("/%d", ++next_sem_ID);
+  res->name = bprintf("/sg-%d", ++next_sem_ID);
   xbt_os_mutex_release(next_sem_ID_lock);
 
+  sem_unlink(res->name);
   res->ps = sem_open(res->name, O_CREAT, 0644, value);
   if ((res->ps == (sem_t *) SEM_FAILED) && (errno == ENAMETOOLONG)) {
     /* Old darwins only allow 13 chars. Did you create *that* amount of semaphores? */
     res->name[13] = '\0';
+    sem_unlink(res->name);
     res->ps = sem_open(res->name, O_CREAT, 0644, value);
   }
   if (res->ps == (sem_t *) SEM_FAILED)