Multithreading

Multithreading is relatively simply in HERCs Prolog implementation. To start a separate thread simply use crack instead of res.

CONDUCTOR
There is an internal synchronisation mechanism, which resembles an orchestra conductor. You can think of it as an object, which sends impulses in the form of ticks, beats and bars. The purpose of conductor is mostly musical. The following three instructions allow to synchronise threads with conductor. It is important to understand when they fail. If a thread waits for a tick or beat or bar and the conductor is suddenly stopped (not paused) then the wait instruction fails. This solution allowes for threads to detect the fact the conductor was stopped and thus take some action (most likely stop the thread). On the other hand, if the conductor is inactive (stopped) and a thread performs a wait instruction (either tick, beat or bar), then the wait instruction does not fail. Instead, it continues waiting. This is a good scenario when you want multiple threads to start execution (perhaps play-back) synchronously at the same time. CONDUCTORS
Apart from global conductor it is possible to create more conductors dynamically. You can create as many of them as you like. Once you have a conductor, you can use all the conductor-related operations in a way similar to object oriented programming. SEMAPHORES
Semaphores are the most basic mechanisms of synchronising threads. You can read about the here. CRITICAL SECTIONS

Critical sections are constructs guarded internally by semaphore. This is basically a clause with a semaphore, which is entered using the wait method. You can call critical section just like any other clause. However, only one thread will be able to enter the critical section at the time. MONITORS

Similar to critical sections but does not store instructions inside. Also, you must supply semaphore entry method (wait/enter) in each subsequent call. ADA-style TASKS