我可以在一个线程中锁定std :: mutex并在其他线程中解锁它吗?这是没有任何特定工程背景的理论问题。我只是好奇。std :: mutex的线程安全
3
A
回答
7
C++标准,[thread.mutex.requirements.mutex]/21和22:
表达
m.unlock()
应良好形成并且具有以下语义:需要:调用线程应拥有互斥锁。
违反了在要求需要条款引起未定义行为。
6
互斥量必须执行的当前线程被锁定,否则,行为是不确定的。
相关问题
- 1. std ::向量,线程安全,多线程
- 2. std :: condition_variable是线程安全的吗?
- 3. 什么更好std :: lock_guard <std::mutex>锁(std :: mutex mutex_var);或std :: mutex mutex_var.lock();
- 4. 是std :: ifstream线程安全和无锁?
- 5. 是std :: to_string线程安全吗?
- 6. C++的基于线程的线程安全的std :: cerr
- 7. 线程安全
- 8. 线程安全从双std :: tuple的std :: vector中读取?
- 9. 使用std :: thread与std :: mutex
- 10. 正在使用std :: deque或std :: priority_queue线程安全吗?
- 11. 是std :: map和std :: set线程安全吗?
- 12. 线程安全:: random_device
- 13. std :: mutex如何在不同的线程中解锁?
- 14. 如何在不同的线程中使用std :: mutex?
- 15. 线程安全
- 16. 线程安全
- 17. 线程安全
- 18. 线程安全
- 19. 线程安全
- 20. 线程安全
- 21. 线程安全的
- 22. C++线程安全和notify_all()
- 23. 的std :: shared_ptr的线程安全的解释
- 24. 线程安全应用程序中的线程安全
- 25. 为什么std :: queue :: empty()不是线程安全的?不应该const函数是线程安全的?
- 26. C++ 11和较新的STL的std ::向量和线程安全
- 27. std :: map和线程安全的奇怪问题
- 28. std :: vector线程对我来说是安全的吗?
- 29. 什么操作在std :: map上是线程安全的?
- 30. 使用线程安全或非线程安全的PHP?
否参见http://www.geeksforgeeks.org/mutex-vs-semaphore/ – yohjp 2014-12-03 07:46:36