Tcl Source Code

View Ticket
Login
Ticket UUID: 872298
Title: Locked access to global variables
Type: RFE Created on: 2004-01-07 11:25:25
Submitter: elfring Assigned to: dkf
Subsystem: 49. Threading Severity:
Priority: 5 Medium Last modified: 2004-01-07 19:56:02
Status: Closed Closed by: dkf
Resolution: Invalid Closed on: 2004-01-07 11:51:18
Version: None
Description:
One part of thread-safe programming is to avoid global 
variables. But some of them must continue to exist 
because they are essential for several functions.
1. Can the direct access (set varname ...) be converted 
to a function call like it is done for "errno" in C?

2. How do you think about to add an option to the 
function "http://tcl.tk/man/tcl8.4/TclCmd/global.htm"?
global -synchronized varname ?varname ...?
User Comments:
dkf added on 2004-01-07 18:51:18:
Logged In: YES 
user_id=79902

This FRQ is invalid because Tcl and the thread extension
already provide all the tools required.  If there is
anything further needed, it should be prototyped within the
context of tcllib first.  On your specific points:

1) http://tcl.tk/man/tcl8.4/TclCmd/trace.htm (and there is
an equivalent mechanism at the C level) allows all Tcl
variable reads and writes to be trapped and clever things done.

2) Global variables are just global to an interpreter
(except for the ::env array, which is deeply magical, messy,
and has proper locking behind the scenes IIRC.) 
Interpreters are always single-threaded; multi-threaded Tcl
has multiple interpreters, but each interp is constrained to
a single thread (this is a fundamental design model thing.)
 Hence a -synchronized option is (mostly) irrelevant as all
variable accesses are already sufficiently synchronized; the
shared-variable stuff in the thread package (which I believe
you already know about) is how you get variables visible
across multiple interpreters.

elfring added on 2004-01-07 19:56:02:
Logged In: YES 
user_id=572001

Thanks for this clear answer.

2) I thought that multiple threads can run in one 
interpreter. - That's not the case at the moment.
I know the tsv functions.

I hope that the libraries I'm working with do also their job 
with requests from different interpreters in a single process 
without thread safety problems.