3.76. kink/thread/THREAD

Provides preemptive threads.

THREAD.spawn starts a new preemptive thread.

Living threads do not prevent the process from exiting, thus they act like Java's daemon threads.

When you spawn a thread, it is automatically detatched from the spawning thread, thus there is no need and/or no way to join the thread. If you want to block until another thread complete its work, use a chan.

3.76.1. THREAD.spawn($thunk)

Spawns a preemptive thread, and runs $thunk in the thread. This fun returns nada.

3.76.2. THREAD.sleep(Seconds)

THREAD.sleep causes the current thread to sleep for the specified Seconds.

Seconds must be a non-negative num of an arbitrary precision. The maximum precision effective in the result depends on the runtime system. For example, in a Kink runtime system on the JVM, the two invocations of STOPWATCH.start in the following program are equivalent. Both tries to sleep 1234 milliseconds.

THREAD.sleep(1.23456) # tries to sleep 1234 milliseconds
THREAD.sleep(1.234)   # tries to sleep 1234 milliseconds