Overview
| Artifact ID: | 4507d7dd8129e40d48e2cf88266f74d67ff8fef9e0e67cd165c36d83f26b8579 |
|---|---|
| Ticket: | 0f439992eff158ca991ee191f89a6bd4c4eb51e9
Checking data consistency for unlocking of mutexes |
| User & Date: | sebres on 2019-05-06 11:48:30 |
Changes
- closedate changed to: "2458609.99202232"
- closer changed to: "sebres"
- icomment:
Firstly, this is a wrong repository for that (please use [/../thread/|thread-repo] for all thread-related issues). Secondly, I assume your proc "perform_command" is running multi-threaded...<br/> Then you've a grave error there - you've a race condition on the mutex creation and locking/unlocking - the mutex stored in tsv shared pcm could be created with thread 1, during a thread 2 still trying to lock another (freshly created) mutex, so it will then try to unlock mutex created within thread 1 later in finally block (because overwritten in tsv). So in order to avoid a race conditions like that, either don't use mutex (tsv-lock is your friend), or you should move the initialization of mutex into master thread (to initialize it once), or you should create mutex like here: <code><pre style="padding-left:10pt"> tsv::lock shared { if {![tsv::exists shared pcm]} { tsv::set shared pcm [thread::mutex create] } } ... thread::mutex lock [tsv::get shared pcm] ... thread::mutex unlock [tsv::get shared pcm] ... </pre></code> Or even still better via "singletone" similar variable: <code><pre style="padding-left:10pt"> if {![tsv::get shared pcm mutex]} { tsv::lock shared { if {![tsv::exists shared pcm]} { tsv::set shared pcm [thread::mutex create] } tsv::get shared pcm mutex } } ... thread::mutex lock $mutex ... thread::mutex unlock $mutex ... </pre></code> Anyway no matter how you would use that, you MUST always ensure that the mutex is created (and referenced) only once in your processing. Otherwise you would get the same RC (so your threads may operate with different mutexes). - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Invalid"
- status changed to: "Closed"