Fix for existing semaphore problem

This commit is contained in:
Dmitry Babokin
2013-11-20 19:19:15 +04:00
parent 40da411fa5
commit 5531586c35

View File

@@ -693,9 +693,19 @@ InitTaskSystem() {
}
char name[32];
sprintf(name, "ispc_task.%d", (int)getpid());
workerSemaphore = sem_open(name, O_CREAT, S_IRUSR|S_IWUSR, 0);
if (!workerSemaphore) {
bool success = false;
srand(time(NULL));
for (int i = 0; i < 10; i++) {
sprintf(name, "ispc_task.%d.%d", (int)getpid(), (int)rand());
workerSemaphore = sem_open(name, O_CREAT, S_IRUSR|S_IWUSR, 0);
if (workerSemaphore != SEM_FAILED) {
success = true;
break;
}
fprintf(stderr, "Failed to create %s\n", name);
}
if (!success) {
fprintf(stderr, "Error creating semaphore (%s): %s\n", name, strerror(errno));
exit(1);
}