SWI-Prolog 5.11.18 Reference Manual: Section 8.2

## 8.2 Monitoring threads

Normal multi-threaded 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 8.5, describing more high-level primitives.

thread_property(?Id, ?Property)
  True if thread Id has Property. Either or both arguments may be unbound, enumerating all relations on backtracking. Calling thread_property/2 does not influence any thread. See also thread_join/2. For threads that have an alias-name, this name is returned in Id instead of the numerical thread identifier. Defined properties are:
  alias(Alias)
    Alias is the alias name of thread Id.
  detached(Boolean)
    Current detached status of the thread.
  status(Status)
    Current status of the thread. Status is one of:
    running
      The thread is running. This is the initial status of a thread. Please note that threads waiting for something are considered running too.
    false
      The Goal of the thread has been completed and failed.
    true
      The Goal of the thread has been completed and succeeded.
    exited(Term)
      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.
    exception(Term)
      The Goal of the thread has been terminated due to an uncaught exception (see throw/1 and catch/3).
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 and CPU time yield different values for each thread.83Getting the CPU-time of a specific thread is not supported on all platforms. On some platforms it returns total process CPU time instead of the thread CPU time. Thread CPU time is supported on MS-Windows and most recent Linux versions.
mutex_statistics
  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 times the calling thread has to wait for the mutex. The collision-count is not available on MS-Windows. Generally collision count is close to zero on single-CPU hardware.