No matching definitions.

tur/rwlock

stdlib/rwlock.tur

POSIX read-write lock (pthread_rwlock_t) wrapped as ptr<void>.

Since: Phase T19-C

defopaque

RwLock

(RwLock)
defn

rwlock-new

(rwlock-new :)

allocate and initialise a new POSIX read-write lock.

An RwLock handle to a heap-allocated pthread_rwlock_t.

(let [rw (rwlock-new)] ...)  ; => RwLock

Since: Phase T19-C

defn

rwlock-rdlock

(rwlock-rdlock [rw : RwLock] :)

acquire a shared read lock, blocking until available.

rwrwlock handle returned by rwlock-new
(rwlock-rdlock rw)

Since: Phase T19-C

defn

rwlock-wrlock

(rwlock-wrlock [rw : RwLock] :)

acquire an exclusive write lock, blocking until available.

rwrwlock handle returned by rwlock-new
(rwlock-wrlock rw)

Since: Phase T19-C

defn

rwlock-try-rdlock

(rwlock-try-rdlock [rw : RwLock] :)

attempt to acquire a shared read lock without blocking.

rwrwlock handle returned by rwlock-new

true if the read lock was acquired; false if a writer currently holds the lock.

(if (rwlock-try-rdlock rw) ...)  ; => bool

Since: Phase T19-C

defn

rwlock-try-wrlock

(rwlock-try-wrlock [rw : RwLock] :)

attempt to acquire an exclusive write lock without blocking.

rwrwlock handle returned by rwlock-new

true if the write lock was acquired; false if the lock is currently held.

(if (rwlock-try-wrlock rw) ...)  ; => bool

Since: Phase T19-C

defn

rwlock-unlock

(rwlock-unlock [rw : RwLock] :)

release a previously acquired read or write lock.

rwrwlock handle returned by rwlock-new
(rwlock-unlock rw)

Since: Phase T19-C

defn

rwlock-free

(rwlock-free [rw : RwLock] :)

destroy the read-write lock and release its memory.

rwrwlock handle returned by rwlock-new
(rwlock-free rw)

Since: Phase T19-C

defmacro

with-read-lock

(with-read-lock [rw & body])

run body holding the rwlock for reading.

rwan RwLock handle (borrowed; not consumed or freed)
bodyone or more forms; the last one's value is returned

The value of the last body form.

(let [rw (rwlock-new)]
    (println (with-read-lock rw 42))   ; => 42
    (rwlock-free rw))

Carries the same two caveats as `with-lock` in stdlib/mutex.tur: `rw` is
evaluated twice (pass a variable, not a call), and a panic inside the body
leaves the lock held.

Since: 2026-08-20

defmacro

with-write-lock

(with-write-lock [rw & body])

run body holding the rwlock for writing.

rwan RwLock handle (borrowed; not consumed or freed)
bodyone or more forms; the last one's value is returned

The value of the last body form.

(let [rw (rwlock-new)]
    (println (with-write-lock rw 7))   ; => 7
    (rwlock-free rw))

Same caveats as `with-read-lock`.

Since: 2026-08-20