- Reference manual
- Multithreaded applications
- Reference manual
Normal multithreaded applications should not need the predicates from this section because almost any usage of these predicates is unsafe. For example checking the existence of a thread before signalling it is of no use as it may vanish between the two calls. Catching exceptions using catch/3 is the only safe way to deal with thread-existence errors.
These predicates are provided for diagnosis and monitoring tasks. See also section 10.5, describing more high-level primitives.
- True if Term is a handle to an existing thread.
- thread_property(?Id, ?Property)
- True if thread Id has Property. Either or both
arguments may be unbound, enumerating all relations on backtracking.
does not influence any thread. See also
For threads that have an alias name, this name is returned in Id
instead of the opaque thread identifier. Defined properties are:
- Alias is the alias name of thread Id.
- Current detached status of the thread.
- Integer identifier for the thread. Can be used as argument to the thread predicates, but applications must be aware that these references are reused.
- Current status of the thread. Status is one of:
- The thread is running. This is the initial status of a thread. Please note that threads waiting for something are considered running too.
- Only if the thread is an engine (see section 11). Indicates that the engine is currently not associated with an OS thread.
- The Goal of the thread has been completed and failed.
- The Goal of the thread has been completed and succeeded.
- The Goal of the thread has been terminated using thread_exit/1 with Term as argument. If the underlying native thread has exited (using pthread_exit()) Term is unbound.
- The Goal of the thread has been terminated due to an uncaught exception (see throw/1 and catch/3).
- If the thread is an engine (see chapter
11), Boolean is
true. Otherwise the property is not present.
- If the thread is an engine that is currently attached to a thread, ThreadId is the thread that executes the engine.
- The amount of memory associated with this thread. This includes the thread structure, its stacks, its default message queue, its clauses in its thread local dynamic predicates (see thread_local/1) and memory used for representing thread-local answer tries (see section 7).
- Thread identifier used by the operating system for the calling thread. Not available on all OSes. This is the same as the Prolog flag system_thread_id for the calling thread. Access to the system thread identifier can, on some systems, be used to gain additional control over or information about Prolog threads.
- thread_statistics(+Id, +Key, -Value)
- Obtains statistical information on thread Id as statistics/2
does in single-threaded applications. This call supports all keys of statistics/2,
although only stack sizes,
epochyield different values for each thread.176There is no portable interface to obtain thread-specific CPU time and some operating systems provide no access to this information at all. On such systems the total process CPU is returned. Thread CPU time is supported on MS-Windows, Linux and MacOSX.
- Print usage statistics on internal mutexes and mutexes associated with
dynamic predicates. For each mutex two numbers are printed: the number
of times the mutex was acquired and the number of collisions:
the number of times the calling thread has to wait for the mutex. The
output is written to
current_outputand can thus be redirected using with_output_to/2.