简体   繁体   中英

Wait and notify equivalent in Objective c?

I am transferring a program from java to Objective C and need to use wait and notify methods that are frequently used for threading in java but can't seem to find any good equivalent in Objective C. I've tried using NSLock object but I don't think it is working. (I'm using [NSLock lock] for waits and [NSLock unlock] for notifies) Is there any good equivalent in Objective C that I haven't been able to find?

There are numerous techniques you could use. You can use NSCondition or POSIX semaphores or dispatch semaphores or by using run loops. Check out the Concurrency Guide and the the Threading Guide .

My personal favourite at the moment is the dispatch semaphore .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM