[問題] unlock of unowned mutex

作者: Caesar08 (Caesar)   2014-08-18 14:32:34
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
問題(Question):
要做readers–writers proble的readers-preference
1.因為不知道每個reader的read時間,因此採用shared_ptr幫忙,讓最後一個reader移除資料
2.使用weak_ptr幫助各個thread拿到shared_ptr
但是mutex的使用規則是 "lock與unlock要由同一個thread完成"
因此要是遇到 "第一個reader讀取完畢,第二個reader還在讀取" 就會有錯
在VC的debug模式下會跳出unlock of unowned mutex
我想問的是
1.這樣的做法是否有誤?
2.unlock of unowned mutex這件事情,該如何處理?
程式碼(Code):(請善用置底文網頁, 記得排版)
http://codepad.org/nGyfou1Y
作者: Caesar08 (Caesar)   2014-08-20 13:56:00
ok 我自己搞定了

Links booklink

Contact Us: admin [ a t ] ucptt.com