Tcl package Thread source code

View Ticket
Login
Ticket UUID: 5f2922dd6d36f043966bbfff9d5293f8b7c5c121
Title: [interp bgerror] is ignored in thread, error sent to other interp instead
Type: Bug Version:
Submitter: pooryorick Created on: 2021-11-10 13:08:02
Subsystem: - New Builtin Commands Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2021-11-10 21:35:31
Resolution: None Closed By: nobody
    Closed on:
Description: (text/x-fossil-wiki)
When the following script is evaluated in a core-8-branch build, the bgerror
procedure registered in the "main" interp is called, while the bgerror
procedure registered in the "worker" interp is ignored:


<code><verbatim>
package require Thread
 
proc bg args {
    puts [list {main error handler} $args]
}
interp bgerror {} bg
 
 
after 0 {
    interp create t1
    set thread [thread::create]
    thread::send -async $thread {
        proc bg args {
            puts stderr [list {thread error handler} $args]
            flush stderr
        }
        interp bgerror {} bg
    }
    thread::send -async $thread {error {an error}} a
}
 
vwait forever
</verbatim></code>

Output:

<code><verbatim>
an error
    while executing
"error {an error}"
Error from thread tid0x7f0b594fb740
an error
{main error handler} {{an error} {-code 1 -level 0 -errorstack {INNER {invokeStk1 open /home/yorick/opt/tcl_thread--2_branch/lib/tclIndex} CALL auto_load_index} -errorcode NONE -errorinfo {an error} -errorline 1}}
</verbatim></code>

If there is no bgerror procedure in the "main" interp, the bgerror procedure in
the "worker" interp is ignored entirely:

<code><verbatim>
package require Thread
 
after 0 {
    interp create t1
    set thread [thread::create]
    thread::send -async $thread {
        proc bg args {
            puts stderr [list {thread error handler} $args]
            flush stderr
        }
        interp bgerror {} bg
    }
    thread::send -async $thread {error {an error}} a
}
 
vwait forever
</verbatim></code>

Output:
<code><verbatim>
Error from thread tid0x7f5f12394640
an error
    while executing
"error {an error}"
Error from thread tid0x7f5f12959740
an error
an error
</verbatim></code>