我正在爲iPhone編寫併發應用程序。 我不知道如果這個代碼:在循環中阻塞相當於空的互斥鎖?
while(!conditionBoolean)
{
// do nothing
// until another thread makes this variable true.
}
makeWork();
等同於以下內容:
[lock lock]; // this lock is locked by another thread
// causing the current to block until it's unlocked
[lock unlock];
makeWork();
如果不是,有什麼區別?
謝謝。
謝謝史蒂夫!你能給出一個信令原語的例子嗎? – wh1t3cat1k 2010-12-08 16:46:05
例如。 `NSConditionLock` - 請參閱http://objc.toodarkpark.net/Foundation/Classes/NSConditionLock.html – 2010-12-08 16:50:03