SYNOPSIS
#include <tcl.h>
void Tcl_ConditionNotify(condPtr)
void Tcl_ConditionWait(condPtr, mutexPtr, timePtr)
void Tcl_ConditionFinalize(condPtr)
void * Tcl_GetThreadData(keyPtr, size)
void Tcl_MutexLock(mutexPtr)
void Tcl_MutexUnlock(mutexPtr)
void Tcl_MutexFinalize(mutexPtr)
int Tcl_CreateThread(idPtr, threadProc, clientData, stackSize, flags)
ARGUMENTS
- Tcl_Condition *condPtr (in)
-
A condition variable, which must be associated with a mutex lock.
- Tcl_Condition *mutexPtr (in)
-
A mutex lock.
- Tcl_Time *timePtr (in)
-
A time limit on the condition wait. NULL to wait forever. Note that a polling value of 0 seconds doesn't make much sense.
- Tcl_ThreadDataKey *keyPtr (in)
-
This identifies a block of thread local storage. The key should be static and process-wide, yet each thread will end up associating a different block of storage with this key.
- int *size (in)
-
The size of the thread local storage block. This amount of data is allocated and initialized to zero the first time each thread calls
Tcl_GetThreadData() . - Tcl_ThreadId *idPtr (out)
-
The refered storage will contain the id of the newly created thread as returned by the operating system.
- Tcl_ThreadId id (in)
-
Id of the thread waited upon.
- Tcl_ThreadCreateProc threadProc (in)
-
This procedure will act as the
main() of the newly created thread. The specified clientData will be its sole argument. - ClientData clientData (in)
-
Arbitrary information. Passed as sole argument to the threadProc.
- int stackSize (in)
-
The size of the stack given to the new thread.
- int flags (in)
-
Bitmask containing flags allowing the caller to modify behavior of the new thread.
- int *result (out)
-
The refered storage is used to place the exit code of the thread waited upon into it.
INTRODUCTION
Beginning with the 8.1 release, the Tcl core is thread safe, which
allows you to incorporate Tcl into multithreaded applications without
customizing the Tcl core. To enable Tcl multithreading support,
you must include the
An important constraint of the Tcl threads implementation is that only the thread that created a Tcl interpreter can use that interpreter. In other words, multiple threads can not access the same Tcl interpreter. (However, as was the case in previous releases, a single thread can safely create and use multiple interpreters.)
Tcl does provide
Restrictions: On some unix systems the pthread-library does not contain the functionality to specify the stacksize of a thread. The specified value for the stacksize is ignored on these systems. Both Windows and Macintosh currently do not support joinable threads. This flag value is therefore ignored on these platforms.
Tcl does provide
Tcl provides
In this release, the Tcl language itself provides no support for creating multithreaded scripts (for example, scripts that could spawn a Tcl interpreter in a separate thread). If you need to add this feature at this time, see the tclThreadTest.c file in the Tcl source distribution for an experimental implementation of a Tcl "Thread" package implementing thread creation and management commands at the script level.
DESCRIPTION
A mutex is a lock that is used to serialize all threads through a piece
of code by calling
A condition variable is used as a signaling mechanism:
a thread can lock a mutex and then wait on a condition variable
with
The caller of
A condition variable can be destroyed after its use by calling
The
The
INITIALIZATION
All of these synchronization objects are self initializing.
They are implemented as opaque pointers that should be NULL
upon first use.
The mutexes and condition variables are
either cleaned up by process exit handlers (if living that long) or
explicitly by calls to
CREATING THREADS
The API to create threads is not finalized at this time. There are private facilities to create threads that contain a new Tcl interpreter, and to send scripts among threads. Dive into tclThreadTest.c and tclThread.c for examples.
PORTABILITY
Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
- Functions:
Tcl_CreateThreadExitHandler() ,Tcl_DeleteThreadExitHandler() ,Tcl_ExitThread() ,Tcl_FinalizeThread() ,Tcl_GetCurrentThread() ,Tcl_ThreadAlert() ,Tcl_ThreadQueueEvent()
PTC MKS Toolkit 10.4 Documentation Build 39.