From 592074adfc88fdc233bf100c91debfa9668fcadf Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 2 Dec 2024 14:41:19 +0000 Subject: [PATCH] Fix [7a56471157]: Consider tip#609 for version >= 3.0.0 --- generic/threadCmd.c | 13 +++++-------- generic/threadPoolCmd.c | 3 +-- tests/thread.test | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/generic/threadCmd.c b/generic/threadCmd.c index fb7b89c..8aa60bd 100644 --- a/generic/threadCmd.c +++ b/generic/threadCmd.c @@ -573,7 +573,7 @@ Init( if (tsdPtr->interp == NULL) { Tcl_Interp *tmpInterp, *mainInterp = interp; memset(tsdPtr, 0, sizeof(ThreadSpecificData)); - /* + /* * Retrieve main interpreter of the thread, only * main interpreter used as default thread-interpreter, * so no childs here, see bug [d4ba38d00d06ebba] @@ -2469,8 +2469,7 @@ ThreadTransfer( * Queue the event and poke the other thread's notifier. */ - Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL); - Tcl_ThreadAlert(thrId); + Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY); /* * (*) Block until the other thread has either processed the transfer @@ -2811,11 +2810,10 @@ ThreadSend( eventPtr->event.proc = ThreadEventProc; if ((flags & THREAD_SEND_HEAD)) { - Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)eventPtr, TCL_QUEUE_HEAD); + Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)eventPtr, TCL_QUEUE_HEAD|TCL_QUEUE_ALERT_IF_EMPTY); } else { - Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)eventPtr, TCL_QUEUE_TAIL); + Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)eventPtr, TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY); } - Tcl_ThreadAlert(thrId); if ((flags & THREAD_SEND_WAIT) == 0) { /* @@ -3089,8 +3087,7 @@ ThreadReserve( evPtr->clbkData = NULL; evPtr->resultPtr = resultPtr; - Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL); - Tcl_ThreadAlert(thrId); + Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY); if (dowait) { while (resultPtr->result == NULL) { diff --git a/generic/threadPoolCmd.c b/generic/threadPoolCmd.c index ed9ccdf..6e62b31 100644 --- a/generic/threadPoolCmd.c +++ b/generic/threadPoolCmd.c @@ -1809,8 +1809,7 @@ SignalWaiter( evPtr = (Tcl_Event *)Tcl_Alloc(sizeof(Tcl_Event)); evPtr->proc = RunStopEvent; - Tcl_ThreadQueueEvent(waitPtr->threadId,(Tcl_Event*)evPtr,TCL_QUEUE_TAIL); - Tcl_ThreadAlert(waitPtr->threadId); + Tcl_ThreadQueueEvent(waitPtr->threadId,(Tcl_Event*)evPtr,TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY); } /* diff --git a/tests/thread.test b/tests/thread.test index e6a0ab1..38f7379 100644 --- a/tests/thread.test +++ b/tests/thread.test @@ -38,7 +38,7 @@ test thread-1.11 {no segfault on 2nd interpreter, bug [d4ba38d00d06ebba]} -body # any other thread invocation before 2nd interpreter gets the thread::id (TSD), # but test-suite calls thread::id command (tcltest, all.tcl and thread.test): set fd [open [list |[info nameofexecutable] << [string map [list {$$load} [tcltest::loadScript]] { - $$load; package require thread + $$load; package require thread interp create ci set l {} ci eval {$$load; package require thread; thread::id}