Concurrency primitives for creating and managing threads.

Besides normal (user) threads, this namespace provides facilities for creating daemon threads, which are threads on which JVM doesn’t wait when exiting.

Thread

Available since version 1.0 (view source)

TYPE

A type for thread.

Thread priority and name can be controlled with mutable and ajustable configuration, which is attached to the thread object.

This type is not available in Dunaj lite, please use Thread+ instead.

Thread+

Available since version 1.0 (view source)

TYPE

A type for thread.

Identical to Thread type, meant to be used in Dunaj lite.

Thread priority and name can be controlled with mutable and ajustable configuration, which is attached to the thread object.

current-thread

Available since version 1.0 (view source)

Usage:
  • (current-thread)

Type signature:
  • () → Thread

Returns current thread.

daemon

Available since version 1.0 (view source)

not referred automatically

MACRO (daemon & body)

Executes body in a new daemon thread, returning immediately to the calling thread. Returns daemon thread. First form in body may be a thread name or options map with :name and :priority as allowed keys.

See also: daemon-call, thread

daemon-call

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (daemon-call f)

  • (daemon-call f name-or-opts)

Type signatures:
  • (AnyFn) → Thread

  • (AnyFn ⨯ (U String+ KeywordMap)) → Thread

Executes f in new daemon thread returning immediately to the calling thread. May supply thread name or options map with :name and :priority as allowed keys. Returns deamon thread.

See also: daemon, thread-call

default-priority

Available since version 1.0 (view source)

not referred automatically

VAR of type Integer+

A thread default priority constant.

ensure-thread-local

Available since version 1.0 (view source)

Usage:
  • (ensure-thread-local thread)

Type signature:
  • (Thread) → nil

Throws if thread is not current thread. Returns nil. Is used to assert that operation is run only in a given thread.

interrupt!

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (interrupt! thread)

Type signature:
  • (Thread) → nil

Interrupts thread. Returns nil.

Code running in thread must support the interuption logic, which is that interrupted? predicate returns true inside interrupted threads and all blocking operations on interrupted thread throw interruption related exception.

See also: interrupted?, thread

interrupted?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (interrupted?)

Type signature:
  • () → Boolean+

Returns true if current thread was interrupted, otherwise returns false. Thread can be interrupted e.g. by cancelling a future.

JVM host specific: Interruption may also manifest itself as InterruptedException when e.g. thread is waiting or sleeping.

join

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (join thread)

  • (join thread timeout)

Type signatures:
  • (Thread) → Boolean+

  • (Thread ⨯ (U IDuration Integer+)) → Boolean+

Waits for a thread to die. Optional timeout can be specified. Returns false if returning due to timeout, true otherwise. Throws if interrupted.

See also: thread, sleep, daemon, interrupt!

max-priority

Available since version 1.0 (view source)

not referred automatically

VAR of type Integer+

A thread maximum priority constant.

min-priority

Available since version 1.0 (view source)

not referred automatically

VAR of type Integer+

A thread minimum priority constant.

pass!

Available since version 1.0 (view source)

Usage:
  • (pass! x new-thread)

Type signature:
  • (IPassableThreadLocal ⨯ (Maybe Thread)) → IPassableThreadLocal

Returns a new object similar to x that has changed its thread ownership to the new-thread. Must be called in the thread that owns the x object. Throws if not called in the owning thread. If the new-thread is nil, object won’t be owned and can be accessed from any thread.

x object must not be used again in any way after this method, returned one should be used instead.

passable-thread-local?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (passable-thread-local? x)

Type signature: Predicate

Returns true if object x satisfies IPassableThreadLocal protocol, false otherwise.

sleep

Available since version 1.0 (view source)

Usage:
  • (sleep duration)

Type signature:
  • ((U IDuration Integer+)) → nil

Waits for a specified duration. Returns nil. Throws if interrupted.

See also: interrupt!, join, thread, daemon

status

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (status thread)

Type signature:
  • (Thread) → Keyword

Returns the thread status. Possible values are :new, :blocked, :runnable, :terminated, :timed-waiting and :waiting.

See also: interrupt!, thread, daemon

thread

Available since version 1.0 (view source)

not referred automatically

MACRO (thread & body)

Executes body in another thread, returning immediately to the calling thread. Returns thread. First form in body may be a thread name or options map with :name, :priority and :daemon as allowed keys.

thread-call

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (thread-call f)

  • (thread-call f name-or-opts)

Type signatures:
  • (AnyFn) → Thread

  • (AnyFn ⨯ (U String+ KeywordMap)) → Thread

Executes f in another thread, returning immediately to the calling thread. Returns thread. May supply thread name or options map with :name, :priority and :daemon as allowed keys.

thread-local?

Available since version 1.0 (view source)

Usage:
  • (thread-local? x)

Type signature: Predicate

Returns true if object x satisfies IThreadLocal protocol, false otherwise.

thread?

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (thread? x)

Type signature: Predicate

Returns true if object x is an instance of Thread type, false otherwise.