Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-11-15
06:21 • Closed ticket [731356ffff]: Win32 non-TLS thread storage patch... plus 8 oth... artifact: 9f2d39443b user: dkf
05:41 • Ticket [731356ffff]: 4 changes artifact: 22ab111765 user: dkf
05:28 • Ticket [731356ffff]: 5 changes artifact: 444581cfb0 user: dgp
05:28 • Add attachment tip138.patch to ticket [731356ffff] artifact: 1be416d62f user: dgp
04:52 • Ticket [731356ffff] Win32 non-TLS thread storage patch... status still Open ... artifact: 68a5801c0c user: dgp
04:21 • Ticket [731356ffff]: 4 changes artifact: 7ac1b1b57e user: dgp
04:15 • Add attachment 731356.patch to ticket [731356ffff] artifact: 319ac26b4c user: dgp
04:15 • Ticket [731356ffff] Win32 non-TLS thread storage patch... status still Open ... artifact: 357e55a373 user: dgp
2003-11-12
01:19 • Ticket [731356ffff]: 4 changes artifact: c7a809df22 user: dkf
2003-11-11
15:13 • Ticket [731356ffff]: 4 changes artifact: 1bf3e08637 user: mistachkin
2003-10-29
17:17 • Ticket [731356ffff]: 5 changes artifact: 17a7fd6329 user: dkf
2003-08-26
05:16 • Ticket [731356ffff]: 4 changes artifact: 7e7475878b user: mistachkin
01:30 • Ticket [731356ffff]: 4 changes artifact: 92533cf46a user: dgp
2003-06-06
10:57 • Ticket [731356ffff]: 5 changes artifact: 838040913b user: mistachkin
2003-05-11
23:51 • Ticket [731356ffff]: 4 changes artifact: 8eb541b264 user: hobbs
19:07 • Ticket [731356ffff]: 5 changes artifact: ed349e5230 user: mistachkin
18:41 • Ticket [731356ffff]: 4 changes artifact: b1e193718f user: mistachkin
08:42 • Ticket [731356ffff]: 4 changes artifact: d9723cfa28 user: mistachkin
00:25 • Ticket [731356ffff]: 4 changes artifact: 881d3fd163 user: kennykb
2003-05-05
13:31 • Ticket [731356ffff]: 4 changes artifact: 5cc13d960e user: mistachkin
13:31 • Add attachment tls5.zip to ticket [731356ffff] artifact: c8712e0908 user: mistachkin
11:34 • Ticket [731356ffff] Win32 non-TLS thread storage patch... status still Open ... artifact: 6bb519eff7 user: mistachkin
2003-05-02
21:03 • Ticket [731356ffff]: 4 changes artifact: d1848841b0 user: nobody
14:03 • New ticket [731356ffff]. artifact: 988899a7f9 user: nobody

Win32 non-TLS thread storage patch...

Closed / Fixed731356ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 23 years ago
Descriptionplain2003-05-02 14:03:05
This patch largely eliminates the need to use the 
Win32 TLS functions, which have serious 
limitations on Windows 95 and NT 4.0.

This patch does NOT modify the "AllocCache" 
related functions to not use Win32 TLS functions.  
However, it could be extended to do so.
nobodyplain2003-05-02 21:03:12
File Added - 49359: tls2.zip
mistachkinplain2003-05-05 11:34:28
File Deleted - 49359: 



File Added - 49534: tls4.zip

Logged In: YES 
user_id=113501

Updated to optionally (via TCL_NO_TLS) remove calls to 
ALL win32 TLS functions, including in the AllocCache 
related functions.  Several leaks fixed (from HEAD, not 
my previous patch).
mistachkinplain2003-05-05 13:31:34
File Deleted - 49534: 



File Added - 49541: tls5.zip

Logged In: YES 
user_id=113501

A few minor changes pursuant to discussions with jyl.
kennykbplain2003-05-11 00:25:37
Logged In: YES 
user_id=99768

This is starting to look good!

Just a few comments before it gets committed:

(1) I'd be a bit more comfortable if STORAGE_CACHE_SLOTS
    were a prime number.  Consider that on at least one
    version of Windows, the thread ID is always a multiple
    of four; this means that the position in the cache will
    also be a multiple of four, giving us only 25 effective
    slots instead of 100. Could we perhaps make it 97
    instead?  Another point is that we might want to
    consider making it a variable instead of a constant. The
    advantage to this is that we could compile tcltest with
    a very, very small value (2 perhaps) and thus make sure
    of test coverage in the cache miss logic.

(2) Several new Tcl* functions have been added. It's
    generally considered good practice to put them in
    tclInt.decls -- but opinions vary about the use of the
    internal stubs table, so I'll be willing to be convinced
    otherwise.

(3) Several functions in the new code lack prologue
    comments.  It would be nice if these could get written
    before committing.

(4) The management scheme that we've arrived at for thread
    specific data is actually platform neutral. Given that
    we've already encountered one platform with an awkward
    hard limit on thread specific data blocks, I'd not be
    willing to lay long odds that there is no other. I
    wonder if we should move the platform-neutral TSD
    management logic to generic/tclThread.c instead of
    calling it Windows code.

(5) What's the difference between TCL_NO_TLS and
    TCL_THREAD_ALLOC_NO_TLS? Do we need both flags?
    (Actually, I wonder, given how badly Windows does this,
    whether we need either, or whether we just want to use
    our own system exclusively.)

Nice job - I'm tempted to say that we should just use it
for ALL our TSD management, irrespective of platform.
mistachkinplain2003-05-11 08:42:35
Logged In: YES 
user_id=113501

Let me address your comments one by one:

(1) I think you are totally right about this. It should be a 
variable that is defaulted to a prime number.

(2) I believe they should go into tclInt.decls, it slipped 
my mind at the time.

(3) The functions in question are most likely the alloc 
cache functions, which strangely never had any 
prologue comments. I believe I added one function to 
this set of functions and I figured "why comment?" if 
there were no other comments regarding these 
particular functions.  All the other functions I added 
should have prologue comments.

(4) I agree about this too.  However, some work will 
need to be done to make this cross-platform.  I have 
proposed to JeffH that we create a new file for this 
subsystem and call it "generic/tclThreadStorage.c".

(5) The difference between these flags is very important, 
actually.  The TCL_NO_TLS flag prevents TLS from being 
used for "high level" thread local storage operations 
(TclpThreadDataKeyInit/TclpThreadDataKeyGet/TclpThre
adDataKeySet).  The TCL_THREAD_ALLOC_NO_TLS 
forces the threaded memory allocator (which is MUCH 
more low level) to NOT use TLS.  These flags should 
definitely stay separate.

Did you notice that I made some changes to tclHash.c 
(the ability to use TclpSysAlloc/TclpSysFree instead of 
ckalloc/ckfree for the non-entry parts of the table that 
need to be dynamically allocated) and tcl.h (a new hash 
key type flag)?  It is my hope that these changes will 
NOT require a TIP, because without them, the threaded 
memory allocator CANNOT use hash tables (due to 
circular dependency issues).

In conclusion, I don't think this patch should be 
committed as is.  I'm still working on some ideas and I 
think that we should make the "new" code cross-
platform. Oh, and I think we should leave in support for 
the "legacy" thread local storage stuff that's in there 
now.
mistachkinplain2003-05-11 18:41:09
Logged In: YES 
user_id=113501

I've made some progress on making this patch 
for "generic".  However, I have a couple questions.  I 
need a way to initialize/finalizing a mutex WITHOUT 
having ckalloc/ckfree being called.  I still need 
InitializeCriticalSection/DeleteCriticalSection (or their 
Unix/Mac equivalents) to be called for the mutex.  The 
threaded memory allocator currently uses 
TclpNewAllocMutex (a very puzzling function) and then 
never finalizes the mutex.  The TclpNewAllocMutex is 
poorly documented and in the case of TCL_THREADS 
without USE_THREAD_ALLOC, unavailable.  I feel there 
should be new platform specific functions added to the 
tcl{Unix|Win|Mac}Thrd.c files, such as 
TclpInitMutex/TclpDeleteMutex.  For platforms that do 
not require these steps, the functions can be empty.
mistachkinplain2003-05-11 19:07:52
Logged In: YES 
user_id=113501

Once I get this patch completed, I would really like to 
benchmark and stress test it.  I haven't been able to get 
tclBench to cooperate as of yet.  Any help on this is 
appreciated.
hobbsplain2003-05-11 23:51:36
Logged In: YES 
user_id=72656

tclbench has a little support for threaded tests, but it may not 
be quite what you want.  What isn't working?
mistachkinplain2003-06-06 10:57:12
Logged In: YES 
user_id=113501

Further research reveals this problem is much worse than I 
originally thought.  Running even the most basic Tcl and/or Tk 
scripts requires a LOT of TLS indexes.  JUST to start wish 
requires 26 TLS indexes.  To start wish and then run a script 
appears to require at least 33 to 40 TLS indexes. The more 
subsystems of Tcl or Tk that are required, the more TLS 
indexes are required.
dgpplain2003-08-26 01:30:59
Logged In: YES 
user_id=80530


TIP 138 is Accepted.  Is this
the implementation patch?
mistachkinplain2003-08-26 05:16:27
Logged In: YES 
user_id=113501

Not exactly. This patch includes more than just the TIP #138 
changes. When I get back home, I will create a new patch for 
HEAD with just the TIP #138 changes.
dkfplain2003-10-29 17:17:47
Logged In: YES 
user_id=79902

This is your reminder call.  I want to get as many Accepted
TIPs as possible to be Final...
mistachkinplain2003-11-11 15:13:42
Logged In: YES 
user_id=113501

This is not the TIP #138 patch, although this does 
incorporate the changes talked about in TIP #138. I will 
create a pure TIP #138 patch as soon as possible, however, I 
will need help making the doc changes.
dkfplain2003-11-12 01:19:19
Logged In: YES 
user_id=79902

I might be able to help with docs.  No promises though.

(When you attach the patch that is purely the TIP impl,
please change the Group field to TIP Implementation.  Thanks!)
dgpplain2003-11-15 04:15:01
File Added - 67528: 731356.patch

Logged In: YES 
user_id=80530


new patch updated to current HEAD.
dgpplain2003-11-15 04:21:50
File Added - 67530: tip138.patch

Logged In: YES 
user_id=80530


Smaller patch that just
implements TIP 138 (?)

someone please review/confirm.
dgpplain2003-11-15 04:52:33
File Deleted - 67530: 



File Added - 67533: tip138.patch

Logged In: YES 
user_id=80530


Corrected TIP 138 patch
for Unix.
dgpplain2003-11-15 05:28:00
File Deleted - 67533: 



File Added - 67547: tip138.patch

Logged In: YES 
user_id=80530


Updated TIP 138 patch
includes documentation.

Please review, correct, and
when satisfied, apply to HEAD.
dkfplain2003-11-15 05:41:38
Logged In: YES 
user_id=79902

Pretty good.  Docs not quite there and we need something to
force this code to be exercised in 'make test'.
dkfplain2003-11-15 06:21:29
Logged In: YES 
user_id=79902

Implemented.
Log in (anonymous is fine) to add a comment.

Attachments: