A problem about thread mutex



hi ,all . I create a thread-pool to call this proc as follows.
but it seems you can't write the tsv "str" if you lock the mutex.
#init var
tsv::set common str null
tsv::set common a { 1 2 3 4 5 6 7 8 9 10}
tsv::set common mutex [thread::mutex create]

#the script called by thread-pool
proc test {} {
# pop one element each times
set id [tsv::lpop common a]
thread::mutex lock [tsv::get common mutex]
tsv::set common str $id
thread::send $mthread {
.t.text insert end "====[tsv::get common str]==="
thread::mutex unlock [tsv::get common mutex]
}

my expected output result is 1 2 3 4 5 6 7 8 9 10
but actual, the result is null 1 2 3 4 5 6 7 8 9 , and click
again ,the next output is 10 1 2 3 4 5 6 7 8 9
Is that sth wrong in my code?
and is there any way you can modify var when lock the mutex?
many thanks
.



Relevant Pages