Id is the alias name if the option alias(name)
is given. Otherwise it is a blob of type thread
.
The anonymous blobs are subject to atom garbage collection. If a thread
handle is garbage collected and the thread is not detached, it
is joined if it has already terminated (see thread_join/2)
and detached otherwise (see thread_detach/1).157Up
to version 7.3.23, anonymous thread handles were integers. Using
integers did not allow for safe checking of the thread's status as the
thread may have died and the handle may have been reused and did not
allow for garbage collection to take care of forgotten threads.
The thread identifier blobs are printed as <thread>(
I,Ptr)
,
where I is the internal thread identifier and Ptr
is the unique address of the identifier. The I is accepted as
input argument for all thread APIs that accept a thread identifier for
convenient interaction from the toplevel. See also thread_property/2.
Options is a list of options. The currently defined
options are below. Stack size options can also take the value inf
or
infinite
, which is mapped to the maximum stack size
supported by the platform.
- alias(AliasName)
- Associate an `alias name' with the thread. This name may be used to refer to the thread and remains valid until the thread is joined (see thread_join/2). If the OS supports it (e.g., Linux), the operating system thread is named as well.
- at_exit(:AtExit)
- Register AtExit as using thread_at_exit/1 before entering the thread goal. Unlike calling thread_at_exit/1 as part of the normal Goal, this ensures the AtExit is called. Using thread_at_exit/1, the thread may be signalled or run out of resources before thread_at_exit/1 is reached.
- debug(+Bool)
- Enable/disable debugging the new thread. If
false
(defaulttrue
), the new thread is created with the propertydebug(false)
and debugging is disabled before the new thread is started. The thread debugging predicates such as tspy/1 and tdebug/0 do not signal threads with the debug property set tofalse
.158Currently, the flag is only used as a hint for the the various debugging primitives, i.e., the system does not really enforce that the target thread stays in nodebug mode. - detached(Bool)
- If
false
(default), the thread can be waited for using thread_join/2. thread_join/2 must be called on this thread to reclaim all resources associated with the thread. Iftrue
, the system will reclaim all associated resources automatically after the thread finishes. Please note that thread identifiers are freed for reuse after a detached thread finishes or a normal thread has been joined. See also thread_join/2 and thread_detach/1.If a detached thread dies due to failure or exception of the initial goal, the thread prints a message using print_message/2. If such termination is considered normal, the code must be wrapped using ignore/1 and/or catch/3 to ensure successful completion.
- inherit_from(+ThreadId)
- Inherit defaults from the given ThreadId instead of the
calling thread. This option was added to ensure that the
__thread_pool_manager
(see thread_create_in_pool/4), which is created lazily, has a predictable state. The following properties are inherited:- The prompt (see prompt/2)
- The typein module (see module/1)
- The standard streams (
user_input
, etc.) - The default encoding (see encoding)
- The default locale (see setlocale/1)
- All prolog flags
- The limits of Prolog stacks (see set_prolog_stack/2)
- global(K-Bytes)
- Set the limit to which the global stack of this thread may grow. If omitted, the limit of the calling thread is used. See also the -G command line option.
- local(K-Bytes)
- Set the limit to which the local stack of this thread may grow. If omitted, the limit of the calling thread is used. See also the -L command line option.
- c_stack(K-Bytes)
- Set the limit to which the system stack of this thread may grow. The
default, minimum and maximum values are system-dependent.159Older
versions used
stack
. This is still accepted as a synonym. - trail(K-Bytes)
- Set the limit to which the trail stack of this thread may grow. If omitted, the limit of the calling thread is used. See also the -T command line option.
The Goal argument is copied to the new Prolog engine. This implies that further instantiation of this term in either thread does not have consequences for the other thread: Prolog threads do not share data from their stacks.