Re: thread::mutex lock problem, a bug?



I've fixed this one. Please checkout and try again.
FYI, this is the (slightly modified) test I used:

tsv::set MUTEX STATE [thread::mutex create]
tsv::set CON_VAR READY [thread::cond create]
tsv::set STATUS STATE BUSY

puts "Try to bring up thread 1"
thread::create {
set f [open /tmp/locks.log a+]
fconfigure $f -buffering line
puts $f "Thread1 [thread::id] is up"
set state_mutex [tsv::get MUTEX STATE]
set con_var_ready [tsv::get CON_VAR READY]
while { 1 } {
puts $f "Thread1 is checking status.."
thread::mutex lock $state_mutex
while { [tsv::get STATUS STATE] ne "READY" } {
puts $f "Thread1 is waiting until READY..."
thread::cond wait $con_var_ready $state_mutex
}
puts $f "Thread1 found that it is READY now"
thread::mutex unlock $state_mutex
puts $f "Thread1 goes to next cycle.."
}
thread::wait
}
puts "Try to bring up thread 2"
thread::create {
set f [open /tmp/locks.log a+]
fconfigure $f -buffering line
puts $f "Thread2 [thread::id] is up"
set state_mutex [tsv::get MUTEX STATE]
while { 1 } {
thread::mutex lock $state_mutex
tsv::set STATUS STATE READY
thread::cond notify [tsv::get CON_VAR READY]
thread::mutex unlock $state_mutex
puts $f "Thread2 set state to ready"
}
thread::wait
}
puts "Try to bring up thread 3"
thread::create {
set f [open /tmp/locks.log a+]
fconfigure $f -buffering line
puts $f "Thread3 [thread::id] is up"
set state_mutex [tsv::get MUTEX STATE]
while { 1 } {
thread::mutex lock $state_mutex
tsv::set STATUS STATE BUSY
thread::mutex unlock $state_mutex
puts $f "Thread3 set state to busy"
}
thread::wait
}


I've been able to test this on Unix only.
Cheers
Zoran

.



Relevant Pages

  • Re: thread::mutex lock problem, a bug?
    ... Thread1 is checking status.. ... puts $f "Thread1 is checking status.." ... thread::mutex lock $state_mutex ... puts $f "Thread2 set state to ready" ...
    (comp.lang.tcl)
  • std out message from threads
    ... puts "Thread 1 started " ... When thread1 starts, it sometimes outputs some error messages as i can ... see it being printed to the ruby console.How do i monitor the text ...
    (comp.lang.ruby)