Posted to tcl by Poor Yorick at Wed Nov 10 12:39:26 GMT 2021view pretty

package require Thread

proc handle_result args {
    puts [list {variable is changed} $args]
}

proc threaderror {tid msg} {
    puts [list {thread error} $tid $msg]
}

proc main thread {
    thread::send -async $thread {
        proc bg args {
            puts oogah!
            puts stderr [list glub! $args]
            flush stderr
        }
        interp bgerror {} bg
        puts zoink
    }
    thread::send -async $thread {error {an error}} a
}


thread::errorproc threaderror
interp create t1
set thread [thread::create]

after 0 [list [namespace which main] $thread]

vwait forever