multithreading - 在 Cocoa 中从不同线程锁定和解锁信号量

标签 multithreading cocoa synchronization nslock

我需要使用某种信号量来保护对互斥区域的访问,但我需要该区域跨越多个线程。这是我在文档中找到的:

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/

相关文章:

java - 安卓 java.lang.IllegalMonitorStateException : object not locked by thread before wait()

multithreading - FIFO队列的共识数量

c# - 如何在ASP.NET中并行化CPU密集型操作

cocoa - 将 NSTextfield 添加到 NSRect

Objective-C 泛型 - 有没有办法使泛型与类匹配(在继承的情况下)

windows - 尝试锁定 Windows

java - Java中多队列和单线程的实现

cocoa - 有没有办法无限期地暂停 NSTHread 并从另一个线程恢复它?

cocoa - 我如何在 Cocoa 中获取应用程序菜单

PHP - 以毫秒为单位的 sleep()