Built-in Module thread

thread

This module provides low-level primitives for working with multiple threads (a.k.a. light-weight processes or tasks) — multiple threads of control sharing their global data space. For synchronization, simple locks (a.k.a. mutexes or binary semaphores) are provided.

The module is optional and supported on SGI IRIX 4.x and 5.x and Sun Solaris 2.x systems, as well as on systems that have a PTHREAD implementation (e.g. KSR).

It defines the following constant and functions:


\begin{excdesc}{error}
Raised on thread-specific errors.
\end{excdesc}


\begin{funcdesc}{start_new_thread}{func\, arg}
Start a new thread. The thread ex...
...ed and
then the thread exits (but other threads continue to run).
\end{funcdesc}


\begin{funcdesc}{exit}{}
This is a shorthand for \code{thread.exit_thread()}.
\end{funcdesc}


\begin{funcdesc}{exit_thread}{}
Raise the \code{SystemExit} exception. When not caught, this will
cause the thread to exit silently.
\end{funcdesc}


\begin{funcdesc}{allocate_lock}{}
Return a new lock object. Methods of locks are described below. The
lock is initially unlocked.
\end{funcdesc}


\begin{funcdesc}{get_ident}{}
Return the \lq thread identifier' of the current thre...
...ay be recycled when a thread exits and
another thread is created.
\end{funcdesc}

Lock objects have the following methods:


\begin{funcdesc}{acquire}{\optional{waitflag}}
Without the optional argument, th...
...return value is 1 if the lock is acquired successfully, 0 if not.
\end{funcdesc}


\begin{funcdesc}{release}{}
Releases the lock. The lock must have been acquired earlier, but not
necessarily by the same thread.
\end{funcdesc}


\begin{funcdesc}{locked}{}
Return the status of the lock:\ 1 if it has been acquired by some
thread, 0 if not.
\end{funcdesc}

Caveats: