需要注意
NSConditon
类[cocoaCondition lock];
while (timeToDoWork <= 0)
[cocoaCondition wait];
timeToDoWork--;
// Do real work here.
[cocoaCondition unlock];
cocoaCondition
中包含了一个锁,以及 Condition 的数据始终使用锁操作来包裹 Condition 的行为,如 signal
和 wait
[cocoaCondition lock];
timeToDoWork++;
[cocoaCondition signal];
[cocoaCondition unlock];