10.1 Creating and destroying Prolog threads
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Multithreaded applications
        • Creating and destroying Prolog threads
          • thread_create/2
          • thread_create/3
          • thread_self/1
          • thread_join/1
          • thread_join/2
          • thread_alias/1
          • thread_detach/1
          • thread_exit/1
          • thread_initialization/1
          • thread_at_exit/1
          • thread_setconcurrency/2
          • thread_affinity/3
    • Packages
Availability:built-in
thread_join(+Id, -Status)
Wait for the termination of the thread with the given Id. Then unify the result status of the thread with Status. After this call, Id becomes invalid and all resources associated with the thread are reclaimed. It is not allowed for two threads to join the same thread and the thread being joined cannot be detached (see the detached(true) option for thread_create/3 and thread_detach/1).

A thread that has been completed without thread_join/2 being called on it is partly reclaimed: the Prolog stacks are released and the C thread is destroyed. A small data structure representing the exit status of the thread is retained until thread_join/2 is called on the thread. Defined values for Status are:

true
The goal has been proven successfully.
false
The goal has failed.
exception(Term)
The thread is terminated on an exception. See print_message/2 to turn system exceptions into readable messages.
exited(Term)
The thread is terminated on thread_exit/1 using the argument Term.

Note that the pthread primitive pthread_join() cannot be interrupted. Some systems provide pthread_timedjoin_np(). If this is provided thread_join/2 is implemented as a loop of timed joins with a 0.25 sec timeout while signals are being tested after each timeout. Such systems allow combining thread_join/2 with call_with_time_limit/2 as well as signalling threads blocked in thread_join/2 using thread_signal/2.