|
2004-01-07
| ||
| 19:56 | • Ticket [872298ffff] Locked access to global variables status still Closed wi... artifact: 0bee9d8641 user: elfring | |
| 18:51 | • Closed ticket [872298ffff]. artifact: 38b030db87 user: dkf | |
| 11:25 | • New ticket [872298ffff]. artifact: 2bc5aa5b61 user: elfring | |
Locked access to global variables
Closed / Invalid872298ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2004-01-07 11:25:25
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 ...?
dkfplain2004-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.
elfringplain2004-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.
Log in (anonymous is fine) to add a comment.