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::- use_module(library(backcomp)).(can be autoloaded)
Sourcethread_at_exit(:Goal)
Run Goal just before releasing the thread resources. This is to be compared to at_halt/1, but only for the current thread. These hooks are run regardless of why the execution of the thread has been completed. When these hooks are run, the return code is already available through thread_property/2 using the result of thread_self/1 as thread identifier. Note that there are two scenarios for using exit hooks. Using thread_at_exit/1 is typically used if the thread creates a side-effect that must be reverted if the thread dies. Another scenario is where the creator of the thread wants to be informed when the thread ends. That cannot be guaranteed by means of thread_at_exit/1 because it is possible that the thread cannot be created or dies almost instantly due to a signal or resource error. The at_exit(Goal) option of thread_create/3 is designed to deal with this scenario.

The Goal is executed with signal processing disabled. This avoids that e.g., thread_signal(Thread, abort) kills the exit handler rather than the thread in the case the body of Thread has just finished when the signal arrives.