TIP 491: Threading Support: phasing out non-threaded builds

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Author:         Jan Nijtmans <jan.nijtmans@gmail.com>
State:          Final
Type:           Project
Vote:           Done
Created:        11-Dec-2017
Post-History:
Keywords:       threads
Tcl-Version:    8.7
Tcl-Branch:     tip-491

Abstract

Since TIP #364 proposed improving thread support, time has come to gradually phase out non-threaded builds on all platforms. On Windows and MacOSX, there are known problems on non-threaded build. But also on UNIX it is becoming increasingly difficult to support both threaded and non-threaded builds. This TIP proposes a gradual deprecation and removal of support for non-threaded builds.

Rationale

Non-threaded builds have a number of known problems:

  • On Windows, DDE and sockets don't work correctly, as they need threads to operate.

  • On UNIX, the new epoll() and kqueue() notifiers (TIP #458) expect the pthread locking to be available.

Further on, the nmake build system uses a different suffix, t, than the autoconf-based build system, a historical mistake that cannot be corrected in a patch release. Let's correct that in Tcl 8.7.

A common misconception is that non-threaded builds are necessary to make vfork() and/or signals work correctly. That may have been true in the past, but not any more: vfork() works fine in threaded builds, the only caveat is that threads started before the vfork don't survive the fork. So, as long as new threads are created after doing the fork, everything should work fine. Applications like AOLserver use this already.

If the developers of Tcl itself can count on threading facilities as part of the foundation, they can be free to use threads when useful in writing the code of the Tcl library itself, without being bound to also invent a thread-free version to cover the --disable-threads configuration.

Proposal

  • Include the following snippet in tcl.h:

     #ifndef TCL_THREADS
     #   define TCL_THREADS 1
     #endif
    

  • Include the following snippet in tclInt.h:

     #if TCL_THREADS && !defined(USE_THREAD_ALLOC)
     #   define USE_THREAD_ALLOC 1
     #endif
    

This means that the (nmake/autoconf) build systems no longer need to explicitly set those two options, a threaded build will be the default. Non-threaded builds are still possible, adding the flag -DTCL_THREADS=0 to the Makefile. Hopefully this further discourages non-threaded builds.

  • In the autoconf build system, remove the --disable-threads option.

  • In the nmake build system, don't use t any longer as suffix, and remove the nothreads and thrdalloc build options.

In Tcl 9:

  • fully remove the use of TCL_THREADS throughout the whole source code. The value is assumed to be 1 everywhere. Non-threaded builds are no longer possible.

Implementation

An implementation of this TIP can be found in the tip-491 branch.

Copyright

This document has been placed in the public domain.

History