Re: Should Linux distros have Tcl threads enabled?

graeme.pietersz@xxxxxxxxx wrote:
I recently reported the incompatibility between Tcl with threads
enabled and the fork command in expect as a bug to my Linux distro.

The obvious solution is to compile without threads enabled, but I was
asked what the disadvantages would be.

Given that they do not have the threads extension in the repos, and I
do not think there is much out there that depends on Tcl being
threaded, I am inclined to think non-threads-enabled should be the

Why am I wrong?

The bug report and comments so far are here:

Any other Mandriva users who have a view on this might want to comment

There are several Tcl extensions that don't work well with threads.

1. Expect uses fork() and Tcl's notifier doesn't work with that, or the
pthread library. The pthread fork behavior is less than ideal. Donal
covered this issue well.

2. TclX's signal handling mechanism is very prone to deadlock when used
with --enable-threads, because it locks a mutex via the Tcl Async API
from what I recall.

To quote from the manual for GNU/Linux (other implementations are
probably very similar, and POSIX doesn't require pthread_mutex_lock() to
be async-signal safe):

"The mutex functions are not async-signal safe. What this means is that
they should not be called from a signal handler. In particular, calling
pthread_mutex_lock or pthread_mutex_unlock from a signal handler may
deadlock the calling thread."

3. Tk's thread support for unix/X11 is iffy. There has been work done
on making Tk thread safe, but Tk still doesn't call XInitThreads(), and
probably won't anytime soon. It seems that the XCB library has a
superior implementation for threaded X11 interfaces anyway, so a
complete rewrite would make more sense (to me). Tk however can be used
with threaded builds, and multiple threads, but only with a single
thread using [package require Tk] as I understand it.


Relevant Pages

  • Re: BLT overhaul
    ... refactor and update BLT graph and vectors to a stubs-enabled ... what is possible and how much work it would be to work on a fork. ... and apply some kind of style guide to it or refactor it even more. ... I have a lot of Tcl ...
  • Re: Tcl8.5/Tclx8.4 fork doesnt work properly
    ... a thread to manage the notifier. ... threaded Tcl uses a number of threads internally). ... dangling lock problems get swept away by starting another executable) ... but for other uses of fork are just trouble. ...
  • Re: fileevent and vwait quiestion
    ... Thread-enabled Tcl + fork? ... So I need to rebuild tcl. ... how exactly notify thread is confused? ...
  • Re: Does recursive call able to print in same page as main call
    ... Yes, but originally, I needed to fork. ... is in taint mode under ActivePerl 5.8.8 (known bug). ... How to launch asynchronously a call to a sub in the same script knowing ... I can't forknor threads's async{}? ...
  • Re: TCL fork not working when using kernel with NPTL
    ... assistance with. ... when I attempt to attach a bash session to a a fifo by ... Thread enabled tcl has problems when forking, ...