Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 865fc5a69dc4e9f5ead665c586d663f04ae455fd3f6a4fc7d3c0f2e1eb7d2d97
Ticket: 0f439992eff158ca991ee191f89a6bd4c4eb51e9
Checking data consistency for unlocking of mutexes
User & Date: elfring on 2019-05-06 12:45:58
Changes

  1. closer changed to: "nobody"
  2. icomment:
    I find the software situation not so clear as desired.
    
    
    > Anyway no matter how you would use that, you MUST always ensure that the mutex is created (and referenced) only once in your processing.
    
    My expectations might be different for these usage constraints.
    
    
    How do you think about to check if any more software surprises can be found by an example script like the following?
    
    
    package require Thread
    set results {}
    
    proc perform_command {} \
    {
    tsv::set [tsv::get shared context] pcm [thread::mutex create]
    thread::mutex lock [tsv::get [tsv::get shared context] pcm]
    tsv::set [tsv::get shared context] pcc [thread::cond create]
    
    try \
       {
       tsv::set [tsv::get shared context] working 0
       tsv::set [tsv::get shared context] finish_notification 0
       } \
    finally \
       {
       proc main_thread_unlock_start {} \
       {thread::mutex unlock [tsv::get [tsv::get shared context] pcm]}
       main_thread_unlock_start
       }
    
    for {set x 1} {$x <= 6} {incr x} \
       {
       set t($x) [thread::create {
                                 proc handle_input {} \
                                 {
                                 thread::mutex lock [tsv::get [tsv::get shared context] pcm]
    
                                 try \
                                    {
                                    puts stderr "[tsv::incr [tsv::get shared context] working] threads are working."
                                    } \
                                 finally \
                                    {
                                    proc handle_input_unlock_begin {} \
                                    {thread::mutex unlock [tsv::get [tsv::get shared context] pcm]}
                                    handle_input_unlock_begin
                                    }
    
                                 thread::mutex lock [tsv::get [tsv::get shared context] pcm]
    
                                 try \
                                    {
                                    tsv::incr [tsv::get shared context] working -1
    
                                    if [tsv::get [tsv::get shared context] finish_notification] \
                                       {
                                       puts stderr {thread::cond notify finish}
                                       thread::cond notify [tsv::get [tsv::get shared context] pcc]
                                       }
                                    } \
                                 finally \
                                    {
                                    proc handle_input_unlock_end {} \
                                    {thread::mutex unlock [tsv::get [tsv::get shared context] pcm]}
                                    handle_input_unlock_end
                                    }
                                 }
    
                                 handle_input
                                 }]
       }
    
    puts stderr "Worker threads were started."
    thread::mutex lock [tsv::get [tsv::get shared context] pcm]
    
    try \
       {
       tsv::set [tsv::get shared context] finish_notification 1
    
       while {[set w [tsv::get [tsv::get shared context] working]] > 0} \
          {
          puts stderr "cond wait finish for $w threads"
          thread::cond wait [tsv::get [tsv::get shared context] pcc] [tsv::get [tsv::get shared context] pcm]
          }
       } \
    finally \
       {
       proc main_thread_unlock_finish {} \
       {thread::mutex unlock [tsv::get [tsv::get shared context] pcm]}
       main_thread_unlock_finish
       }
    
    global results
    lappend results [llength [thread::names]]
    #thread::cond destroy [tsv::get [tsv::get shared context] pcc]
    #thread::mutex destroy [tsv::get [tsv::get shared context] pcm]
    }
    
    proc repeat_command {} \
    {
    for {set x 1} {$x <= 12} {incr x} \
       {
       puts stderr "$x. run"
       tsv::set shared context $x
       perform_command
       }
    }
    
    proc run_analysis {} \
    {
    repeat_command
    global results
    
    if [llength ${results}] \
       {
       proc report {} \
       {
       global results
    
       foreach k ${results} \
          {
          dict incr counts $k
          }
    
       set delimiter |
       puts [join {{"still running threads"} incidence} ${delimiter}]
    
       dict for {k v} ${counts} \
          {
           puts "$k${delimiter}$v"
          }
       }
    
       report
       } \
    else \
       {
       puts stderr {No result for this analysis!}
       }
    }
    
    run_analysis
    
  3. login: "elfring"
  4. mimetype: "text/plain"
  5. resolution changed to: "Later"
  6. severity changed to: "Important"
  7. status changed to: "Open"