Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2004-11-25
23:07 • Closed ticket [994229ffff]: tsv::lock doesn't lock between threads plus ... artifact: 2a7200b2c6 user: vasiljevic
2004-07-22
04:12 • Ticket [994229ffff]: 4 changes artifact: 474a5cdb2b user: vasiljevic
2004-07-20
23:35 • Ticket [994229ffff]: 4 changes artifact: 09a543994e user: tsanders
17:01 • Ticket [994229ffff]: 4 changes artifact: b80480d6c8 user: vasiljevic
02:27 • New ticket [994229ffff]. artifact: 1a00ecab30 user: nobody

tsv::lock doesn't lock between threads

Closed / Fixed994229ffffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2004-07-20 02:27:11
A [tsv::lock <arrayName>] will not prevent two threads 
from accessing the tsv array.

% puts $tcl_version
8.4
% array get tcl_platform
osVersion 7.3.0 byteOrder bigEndian threaded 1 machine 
{Power Macintosh} platform unix os Darwin user ts
anders wordSize 4
% package require Thread
2.5

Testcase:

package require Thread

tsv::set global true 1
tsv::set global false 0

set a [thread::create]
set b [thread::create]
set ::finish 0

thread::send $a [list set x [thread::id]]; # main thread 
id
thread::send -async $a {
    set ::finish 0
    puts "a: [thread::id]"
    tsv::lock global {
        puts "a: has global lock ([tsv::get global true])"
        tsv::set global true 2
        vwait ::finish
    }
    puts "a: released global lock"
    thread::send $::x {incr ::finish}
}

# kick thread a out of lock
after 5000 {thread::send $a {incr ::finish}}

after 1000 {
    thread::send -async $b {
        puts "b: [thread::id], waiting for global lock"
        tsv::lock global { puts "b: got global lock 
([tsv::get global true])" }
        puts "b: released global lock"
    }
}

vwait ::finish


Output:

a: 25173504
a: has global lock (1)
b: 25174528, waiting for global lock
b: got global lock (2)
b: released global lock
a: released global lock


You can see that b was able to obtain the lock and 
access the tsv global array data while thread 'a' had the 
lock.

I saw one message in the forum about this also but the 
person never got an answer there.   Any clues?  I 
peeked at the code and didn't see an immediate problem 
but I'm not familiar with that code at all.

sanders012<at>earth.com
vasiljevicplain2004-07-20 17:01:44
Logged In: YES 
user_id=95086

Yes. This is still wrong in the 2.5.1 
 
I'm trying to catch up with 2.6 which corrects this problem. 
I still need to cleanup the docs and write test-suite for 
tpool and tsv commands.  
As the matter of fact, I can already check-in the changes  
in the head branch so you can test it out. 
 
Given the high-load I have at work, I cannot promise to 
release 2.6 in next 3-4 weeks. But, the cvs head should be stable 
enough to use. Please do checkout the head in 2-3 days again 
and give it a try. 
 
I will leave this bug report open until I release the 2.6 version.
tsandersplain2004-07-20 23:35:56
Logged In: YES 
user_id=1087228

A quick test against HEAD using my testcase (and 
application) seems to be working ok.  I'll let you know if any 
issues pop up.

I'll also watch for any further checkin's and track the changes.

Thanks for the quick response and all the work on the thread 
library too.
vasiljevicplain2004-07-22 04:12:16
Logged In: YES 
user_id=95086

I have updated the cvs head with my latest changes. 
Please try it again. Also, read the ChangeLog to see 
what is new.

This bug-report will be left open until I really release 
the 2.6. On todo list are just tpool.test, tsv.test and
ttrace.test
files which need to be written new.
vasiljevicplain2004-11-25 23:07:16
Logged In: YES 
user_id=95086

Closing this one since the 2.6 is underway
Log in (anonymous is fine) to add a comment.