Tcl Source Code

View Ticket
Login
Ticket UUID: 999084
Title: re-entrant Tcl_Finalize()
Type: Patch Version: None
Submitter: dgp Created on: 2004-07-28 00:05:09
Subsystem: 02. Event Loops Assigned To: dgp
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2004-07-30 22:16:28
Resolution: Accepted Closed By: dgp
    Closed on: 2004-07-30 15:16:28
Description:
This patch moves the ExitHandler calls
of Tcl_Finalize() outside of the
TclpInitLock-ed region.

This will avoid deadlocks like the one
seen in Tk Bug 714956, when the
execution of a registered ExitHandler
causes another, nested, call to
Tcl_Finalize().

This patch should be safe, because
the exitHandler loop is careful to always
pull the next handler to run from the
beginning of the loop, and discard each
as it is run, terminating only when the
list is empty.

The rest of Tcl_Finalize(), protected
by a TclpInitLock region, should, we
hope, be prevented from making
a nested call back into Tcl_Finalize().

Please review.
User Comments: dgp added on 2004-07-30 22:16:28:
Logged In: YES 
user_id=80530


Thanks!  Applying for 8.4.8 and 8.5.

vasiljevic added on 2004-07-29 20:04:22:
Logged In: YES 
user_id=95086

I see no obvious problems.  
A side-effect, though, is that, when Tcl_Finalize is called 
simultaneously by two threads, both of them will execute 
exit callbacks. Each exit callback will be run once, but you  
never know in which thread this may happen. 
Strictly speaking, this should pose no problems, provided that 
exit callbacks are really app-wide and do not assume any 
thread local storage ownerships and such. Actually, they should 
be designed as such in the first place.

dgp added on 2004-07-28 21:25:42:
Logged In: YES 
user_id=80530


passing on to someone I think
knows Tcl_Finalize() better.

This patch fixes a bug, but does
it cause any new trouble?

dgp added on 2004-07-28 07:05:09:

File Added - 95491: finalize.patch

Attachments: