17. Jobs and threads

Apply module implements job que and threading.

All functions and symbols are in “jobque” module, use require to get access to it.

require jobque

17.1. Handled structures

JobStatus
JobStatus implicit.isReady() : bool()

Weather or not the job is completed.

JobStatus implicit.isValid() : bool()

If the job status object is valid.

JobStatus implicit.size() : int()

Number of remaining elements, which were previously appended.

Properties
  • isReady : bool

    • isValid : bool

    • size : int

Job status indicator (ready or not, as well as entry count).

Channel
Channel implicit.isEmpty() : bool()

Weather there are no remaining elements in the pipe.

Channel implicit.total() : int()

Total number of elements in the pipe.

Properties
  • isEmpty : bool

    • total : int

Channel provides a way to communicate between multiple contexts, including threads and jobs. Channel has internal entry count.

LockBox

Lockbox. Similar to channel, only for single object.

Atomic32

Atomic 32 bit integer.

Atomic64

Atomic 64 bit integer.

17.2. Channel, JobStatus, Lockbox

lock_box_create() : LockBox?()

Creates lockbox.

lock_box_remove(box: LockBox?& implicit)

Warning

This is unsafe operation.

Destroys lockbox.

Arguments
append(channel: JobStatus? implicit; size: int) : int()

Increase entry count to the channel.

Arguments
channel_create() : Channel?()

Warning

This is unsafe operation.

Creates channel.

channel_remove(channel: Channel?& implicit)

Warning

This is unsafe operation.

Destroys channel.

Arguments
add_ref(status: JobStatus? implicit)

Increase reference count of the job status or channel.

Arguments
release(status: JobStatus?& implicit)

Decrease reference count of the job status or channel. Object is delete when reference count reaches 0.

Arguments
join(job: JobStatus? implicit)

Wait until channel entry count reaches 0.

Arguments
notify(job: JobStatus? implicit)

Notify channel that entry is completed (decrease entry count).

Arguments
notify_and_release(job: JobStatus?& implicit)

Notify channel or job status that entry is completed (decrease entry count) and decrease reference count of the job status or channel.

Arguments
job_status_create() : JobStatus?()

Creates job status.

job_status_remove(jobStatus: JobStatus?& implicit)

Warning

This is unsafe operation.

Destroys job status.

Arguments

17.3. Queries

get_total_hw_jobs() : int()

Total number of hardware threads supporting job system.

get_total_hw_threads() : int()

Total number of hardware threads available.

is_job_que_shutting_down() : bool()

Returns true if job que infrastructure is shut-down or not initialized.

17.4. Internal invocations

new_job_invoke(lambda: lambda<():void>; function: function<():void>; lambdaSize: int)

Creates clone of the current context, moves attached lambda to it.

Arguments
  • lambda : lambda<void>

  • function : function<void>

  • lambdaSize : int

new_thread_invoke(lambda: lambda<():void>; function: function<():void>; lambdaSize: int)

Creates clone of the current context, moves attached lambda to it.

Arguments
  • lambda : lambda<void>

  • function : function<void>

  • lambdaSize : int

new_debugger_thread(block: block<():void>)

Creates a new thread for debugging purposes (tick thread).

Arguments
  • block : block<void> implicit

17.5. Construction

with_lock_box(block: block<(LockBox?):void>)

Creates LockBox, makes it available inside the scope of the block.

Arguments
  • block : block<( LockBox ?):void> implicit

with_channel(block: block<(Channel?):void>)

Creates Channel, makes it available inside the scope of the block.

Arguments
  • block : block<( Channel ?):void> implicit

with_channel(count: int; block: block<(Channel?):void>)

Creates Channel, makes it available inside the scope of the block.

Arguments
  • count : int

  • block : block<( Channel ?):void> implicit

with_job_status(total: int; block: block<(JobStatus?):void>)

Creates JobStatus, makes it available inside the scope of the block.

Arguments
  • total : int

  • block : block<( JobStatus ?):void> implicit

with_job_que(block: block<():void>)

Makes sure jobque infrastructure is available inside the scope of the block.

Arguments
  • block : block<void> implicit

17.6. Atomic

atomic32_create() : Atomic32?()

Creates atomic 32 bit integer.

atomic32_remove(atomic: Atomic32?& implicit)

Warning

This is unsafe operation.

Destroys atomic 32 bit integer.

Arguments
with_atomic32(block: block<(Atomic32?):void>)

Creates Atomic32, makes it available inside the scope of the block.

Arguments
  • block : block<( Atomic32 ?):void> implicit

set(atomic: Atomic32? implicit; value: int)

Set atomic integer value.

Arguments
  • atomic : Atomic32 ? implicit

  • value : int

get(atomic: Atomic32? implicit) : int()

Get atomic integer value.

Arguments
inc(atomic: Atomic32? implicit) : int()

Increase atomic integer value and returns result.

Arguments
dec(atomic: Atomic32? implicit) : int()

Decrease atomic integer value and returns result.

Arguments
atomic64_create() : Atomic64?()

Creates atomic 64 bit integer.

atomic64_remove(atomic: Atomic64?& implicit)

Warning

This is unsafe operation.

Destroys atomic 64 bit integer.

Arguments
with_atomic64(block: block<(Atomic64?):void>)

Creates Atomic64, makes it available inside the scope of the block.

Arguments
  • block : block<( Atomic64 ?):void> implicit

set(atomic: Atomic64? implicit; value: int64)

Set atomic integer value.

Arguments
  • atomic : Atomic64 ? implicit

  • value : int64

get(atomic: Atomic64? implicit) : int64()

Get atomic integer value.

Arguments
inc(atomic: Atomic64? implicit) : int64()

Increase atomic integer value and returns result.

Arguments
dec(atomic: Atomic64? implicit) : int64()

Decrease atomic integer value and returns result.

Arguments