我需要使用某种信号量来保护对互斥区域的访问,但我需要该区域跨越多个线程。这是我在文档中找到的:
Warning: The NSLock class uses POSIX threads to implement its locking behavior. When sending an unlock message to an NSLock object, you must be sure that message is sent from the same thread that sent the initial lock message. Unlocking a lock from a different thread can result in undefined behavior.
我记得我读到过这是一种防止编程错误的方法。这个说法正确吗? 我从文档中阅读了线程指南,但我找不到任何其他可以使用的类来允许从不同的线程锁定和解锁。 Cocoa 中还有其他解决方案可以做到这一点吗? 谢谢!
最佳答案
关于multithreading - 在 Cocoa 中从不同线程锁定和解锁信号量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5361250/