我可以在一個線程中鎖定std :: mutex並在其他線程中解鎖它嗎?這是沒有任何特定工程背景的理論問題。我只是好奇。std :: mutex的線程安全
3
A
回答
7
C++標準,[thread.mutex.requirements.mutex]/21和22:
表達
m.unlock()
應良好形成並且具有以下語義:需要:調用線程應擁有互斥鎖。
違反了在要求需要條款引起未定義行爲。
6
互斥量必須執行的當前線程被鎖定,否則,行爲是不確定的。
相關問題
- 1. 如何安全刪除成員std :: mutex?
- 2. std :: vectors線程安全嗎?
- 3. std :: random_shuffle線程安全嗎?
- 4. std ::向量,線程安全,多線程
- 5. std :: condition_variable是線程安全的嗎?
- 6. 帶線程安全std :: cout的死鎖
- 7. 使用std :: mutex成員和運算符<<插入過載的線程安全訪問std :: ofstream成員?
- 8. 什麼更好std :: lock_guard <std::mutex>鎖(std :: mutex mutex_var);或std :: mutex mutex_var.lock();
- 9. std :: shared_future operator =線程安全/原子?
- 10. 如何安全地停止std線程?
- 11. 是std :: ifstream線程安全和無鎖?
- 12. 是std :: regex線程安全嗎?
- 13. 是std :: to_string線程安全嗎?
- 14. 是std :: polar線程安全嗎?
- 15. std :: unique_lock <std::mutex>或std :: lock_guard <std::mutex>?
- 16. 線程安全
- 17. C++的基於線程的線程安全的std :: cerr
- 18. 線程安全從雙std :: tuple的std :: vector中讀取?
- 19. 是從std :: map或std :: set線程安全的複製嗎?
- 20. 使用std :: thread與std :: mutex
- 21. 將std :: mutex作爲參數的成員函數的線程化
- 22. java線程安全:線程安全嗎?
- 23. 線程安全:: random_device
- 24. 正在使用std :: deque或std :: priority_queue線程安全嗎?
- 25. 是std :: map和std :: set線程安全嗎?
- 26. 對boost :: asio管理的線程池使用std :: mutex
- 27. 是std :: mutex足夠用於線程之間的數據同步
- 28. std :: mutex如何在不同的線程中解鎖?
- 29. 如何在不同的線程中使用std :: mutex?
- 30. 安全出口程序Win32的C++從分離的std ::線程
否參見http://www.geeksforgeeks.org/mutex-vs-semaphore/ – yohjp 2014-12-03 07:46:36