tur/barrier
stdlib/barrier.tur
counting barrier: N threads rendezvous, then all proceed.
Example
(let [b (barrier-new 3)]
;; ... three threads each call (barrier-wait b) ...
(barrier-free b))
Since: 2026-08-20
defopaque
linear
Barrier
(Barrier)
defn
barrier-new
(barrier-new [n : int] :)
create a barrier that releases every n-th waiter.
Parameters
| n | number of threads that must rendezvous; must be >= 1 |
Returns
A Barrier handle. Free it with barrier-free.
Example
(let [b (barrier-new 3)] (barrier-free b))
Since: 2026-08-20
defn
barrier-wait
(barrier-wait [^borrow b : Barrier] :)
block until n threads have arrived, then release them all.
Parameters
| b | the Barrier to wait on (borrowed) |
Returns
true for exactly ONE of the n threads released -- the one whose arrival tripped the barrier -- and false for the rest. Mirrors PTHREAD_BARRIER_SERIAL_THREAD, and is what lets a single thread run the between-phases work (swap buffers, print a summary) with no extra lock.
Example
(if (barrier-wait b) (println "phase done") 0)
Since: 2026-08-20
defn
barrier-free
(barrier-free [b : Barrier] :)
destroy the barrier and release its memory.
Parameters
| b | the Barrier to destroy (consumed) |
Example
(barrier-free b)
Since: 2026-08-20
Internal definitions
barrier/autolink-hint-- hoist the TurBarrier layout to file scope.