Overview
| Artifact ID: | 7ec2e0605d5625d53eb3a1c0c315063ebd639c97e7bc37c63b323b0ad51f294f |
|---|---|
| Ticket: | f583715154c6f33d621418e8c9f6dfae5cc5ebc4
Fileevent runs in the wrong thread |
| User & Date: | sbron on 2020-01-10 12:14:24 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
The script shown below sets up an async socket in a helper thread and then transfers the channel to the main thread. In the main thread, a writable file event handler is then configured on the channel. However, when this event handler is invoked, it runs in the helper thread rather than the main thread. <verbatim> package require Thread set tid [thread::create] puts "Main thread: [thread::id]" puts "Helper thread: $tid" set fd [thread::send $tid { set fd [socket -async 8.8.8.8 53] thread::detach $fd set fd }] thread::attach $fd fileevent $fd writable { puts "Fileevent thread: [thread::id]" exit } vwait forever </verbatim> The output of the script is something like:<verbatim> Main thread: tid0x7f868f4b5680 Helper thread: tid0x7f868ddbb700 Fileevent thread: tid0x7f868ddbb700 </verbatim> System: openSUSE Leap 15.1 x86_64 I initially opened this issue against the thread extension ([https://core.tcl-lang.org/thread/tktview/d481f15516|d481f15516]). However, it appears to be an issue in the Tcl core caused by the use of an internal event handler to deal with the async connect. I believe this is a different issue than [https://core.tcl-lang.org/tcl/info/815e246806|815e246806]. I created a patch that reconfigures the internal event handler in the new thread when the channel is transferred. It fixes the problem in all scenarios I could come up with sofar. - foundin changed to: "trunk (9.0a2)"
- is_private changed to: "0"
- login: "sbron"
- priority changed to: "5 Medium"
- private_contact changed to: "8475f421649231f1e116ac602bea4537d2b027b4"
- resolution changed to: "None"
- severity changed to: "Severe"
- status changed to: "Open"
- submitter changed to: "sbron"
- subsystem changed to: "49. Threading"
- title changed to: "Fileevent runs in the wrong thread"
- type changed to: "Bug"