Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为 iphone dev 实现 pthread_rwlock_t 的包装器。文档说在获取写锁后获取读锁是未定义的。POSIX 是否允许我查询我是否已经拥有写锁?或者,防止这种情况发生的最好方法是什么?
谢谢!
您的包装器应该跟踪它是否已经在该线程中持有写锁。您可以通过多种方式做到这一点,但看看流行的库 ilke boost或ACE是如何做到的可能会有所帮助。
您应该考虑使用其中一个现有的库,并跳过重新实现之前可能已经完成的工作的担忧和努力。