Tk Source Code

View Ticket
Login
Ticket UUID: b298b92ba77684aa08f11c3e676f3db0837ec0b4
Title: Possible Tk regression when loading into threads
Type: Bug Version: 8.6.18, 9.0.5, 9.1.0
Submitter: anonymous Created on: 2025-02-25 14:55:52
Subsystem: (unused) Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-11-10 16:31:27
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-11-10 16:31:27
Description:
Interpreter exits execution running the following script under Tcl/Tk 9.0.1, but runs fine in 8.6.9-14 (Linux x64).


package require Thread

for {set c 1} {$c < 10000} {incr c} {
	set t1 [thread::create {package require Tk; thread::wait}]
	puts "$c $t1"
	after 100
	thread::release  $t1
}
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-11-10 16:31:27:

Serhiy, many thanks! Merged into main, core-9-0-branch, and core-8-6-branch by commits [fa8a84bb], [d497451e], and [9ef9af85].


serhiy.storchaka added on 2026-10-23 20:52:22:

This is not a regression: it happens in all versions, 8.6.9 included, once each thread creates a widget with a font. The script in the report passes in 8.6 and 9.1 only because no font is used there.

When a display is closed, the close hook of Xft frees its cached glyphs through RENDER after the close hook of RENDER has already run. That registers RENDER again for the dying display, and a new display opened later at the same address inherits the stale extension codes, so its RENDER requests go out with wrong opcodes and the X server replies with BadRequest or BadLength.

Fixed on branch x11-render-before-xft ([423012d795]): TkpOpenDisplay() initializes RENDER before Xft, so that the RENDER hook runs last. With it, 40 threads in a row, each creating labels, run without errors; without it, every run fails within a few threads.


anonymous added on 2025-02-25 15:06:09:
I've tested thread pools with the same result when a thread is released and then recreated. If I use a fixed pool size where min=max, then there is no issue.

It appears to have something to do with the thread id being reused and then Tk being loaded into this thread.

anonymous (claiming to be stever) added on 2025-02-25 14:57:27:
Submitted by stever (Steve Redler IV)