sem_init在OS X [英] sem_init on OS X
问题描述
我的工作,它使用pthread和信号灯库一些code。该sem_init函数工作我的Ubuntu的机器上很好,但在OS X上sem_init函数完全没有影响。是不是有什么毛病库还是有那么这是一种不同的方式?这是code我使用的测试。
I am working on some code which uses the pthread and semaphore libraries. The sem_init function works fine on my ubuntu machine, but on OS X the sem_init function has absolutely no effect. Is there something wrong with the library or is there a different way of doing it? This is the code I am using to test.
sem_t sem1;
sem_t sem2;
sem_t sem3;
sem_t sem4;
sem_t sem5;
sem_t sem6;
sem_init(&sem1, 1, 1);
sem_init(&sem2, 1, 2);
sem_init(&sem3, 1, 3);
sem_init(&sem4, 1, 4);
sem_init(&sem5, 1, 5);
sem_init(&sem6, 1, 6);
的值似乎是随机数,并且它们的sem_init呼叫后不改变
The values appear to be random numbers, and they do not change after the sem_init call.
推荐答案
未命名信号不支持,你需要使用命名信号。
Unnamed semaphores are not supported, you need to use named semaphores.
要使用命名信号,而不是无名信号量,使用 sem_open
而不是 sem_init
,并使用 sem_close
和 sem_unlink
而不是 sem_destroy
。
To use named semaphores instead of unnamed semaphores, use sem_open
instead of sem_init
, and use sem_close
and sem_unlink
instead of sem_destroy
.
这篇关于sem_init在OS X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!