YAP 7.1.0
Monitoring Threads

Normal multi-threaded applications should not need these the predicates from this section because almost any usage of these predicates is unsafe. More...

Detailed Description

Normal multi-threaded applications should not need these 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


Class Documentation

◆ current_thread/2

class current_thread/2

current_thread(+ Id, - Status)

Enumerates identifiers and status of all currently known threads Calling current_thread/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 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_property/2

class thread_property/2

thread_property(? Id, ? Property)

Enumerates the properties of the specified thread Calling thread_property/2 does not influence any thread See also thread_join/2 For threads that have an alias-name, this name can be used in Id instead of the numerical thread identifier Property is one of:

  • status( Status) The thread status of a thread (see below)
  • alias( Alias) The thread alias, if it exists
  • at_exit( AtExit) The thread exit hook, if defined (not available if the thread is already terminated)
  • detached( Boolean) The detached state of the thread
  • stack( Size) The thread stack data-area size
  • trail( Size) The thread trail data-area size
  • system( Size) The thread system data-area size

◆ thread_statistics/3

class thread_statistics/3

thread_statistics(+ Id, + Key, - Value)

Obtains statistical information on thread Id as statistics/2 does in single-threaded applications This call returns all keys of statistics/2 , although only information statistics about the stacks and CPU time yield different values for each thread

  • 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 Windows as this would break portability to Windows-95/98/ME or significantly harm performance Generally collision count is close to zero on single-CPU hardware

  • threads

Prints a table of current threads and their status