No matching definitions.

tur/sync

stdlib/sync.tur

Once and Semaphore synchronization primitives.

Since: Phase T19-C

defn

once-flag-new

(once-flag-new :ptr<void>)

allocate and initialise a pthread_once_t flag on the heap.

A :ptr<void> to the new once-flag; pass to once-call and once-flag-free.

(def flag (once-flag-new))

Since: Phase T19-C

defn

once-call

(once-call [flag :ptr<void> init-fn :ptr<void>] :nil)

call init-fn exactly once for the lifetime of flag, regardless of concurrency.

flagonce-flag pointer from once-flag-new
init-fnzero-argument C function pointer to invoke at most once

Since: Phase T19-C

defn

once-flag-free

(once-flag-free [flag :ptr<void>] :nil)

free a once-flag allocated by once-flag-new.

flagonce-flag pointer from once-flag-new

Since: Phase T19-C

defn

sem-new

(sem-new [initial :int] :ptr<void>)

allocate a counting semaphore initialised to initial.

initialstarting count (0 = locked, >0 = permits available)

A :ptr<void> handle to the semaphore; pass to sem-acquire, sem-release, sem-free.

(def s (sem-new 1))  ; binary semaphore (mutex-like)

Since: Phase T19-C

defn

sem-acquire

(sem-acquire [s :ptr<void>] :nil)

decrement the semaphore; blocks until count > 0.

ssemaphore pointer from sem-new

Since: Phase T19-C

defn

sem-release

(sem-release [s :ptr<void>] :nil)

increment the semaphore and wake one blocked acquirer.

ssemaphore pointer from sem-new

Since: Phase T19-C

defn

sem-free

(sem-free [s :ptr<void>] :nil)

destroy and free a semaphore allocated by sem-new.

ssemaphore pointer from sem-new

Since: Phase T19-C