iPhone:我如何实现信号量? [英] iPhone: How can I implement semaphore?
问题描述
有人可以解释我如何在Objective-C中实现信号量吗?
我在这个主题上做了很多谷歌搜索,但我没有发现任何可以解释的事情。
Can somebody explain how I can implement semaphore in Objective-C? I did a lot of google searching on the topic, but I haven't found anything understandable.
推荐答案
C apis可以在 sys / semaphore.h
中找到。在你的objc包装器/实现中使用它们。
C apis can be found in sys/semaphore.h
. use these in your objc wrapper/implementation.
这个基本示例是google搜索sem_trywait示例时的第一个结果。它告诉你如何使用这些apis。
this basic example is the first result when 'sem_trywait example' is googled. it shows you how you can use these apis.
然后一个最小的界面将采用这种形式:
then a minimal interface would take this form:
@interface MONSemaphore : NSObject
{
sem_t semaphore;
}
- (int)close;
- (int)destroy;
/* .. and the rest of the interface you wrap and make public here .. */
@end
但您可能还希望该对象从客户端抽象出init和destruct例程。
but it's likely that you will also want the object to abstract the init and destruct routines from the client.
这篇关于iPhone:我如何实现信号量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!