No matching definitions.

tur/thread

stdlib/thread.tur

POSIX thread spawn, join, and detach wrappers.

Since: Phase T19-C

defn

thread-spawn-fn

(thread-spawn-fn [fn-ptr :ptr<void> arg :ptr<void>])

spawn a new OS thread calling fn-ptr with arg.

fn-ptrC function pointer of type void *(*)(void *)
argopaque argument forwarded to fn-ptr

A ptr<void> thread handle that must be passed to thread-join or thread-detach.

(let [t (thread-spawn-fn my-fn arg)] (thread-join t))  ; => ptr<void>

Since: Phase T19-C

defn

thread-join

(thread-join [t :ptr<void>])

wait for a thread to finish and free its handle.

tthread handle returned by thread-spawn-fn
(thread-join t)

Since: Phase T19-C

defn

thread-detach

(thread-detach [t :ptr<void>])

detach a thread (it cleans up itself on exit) and free the handle.

tthread handle returned by thread-spawn-fn
(thread-detach t)

Since: Phase T19-C

defn

thread-id

(thread-id)

return an integer identifier for the calling OS thread.

The current thread's pthread_t value cast to int64_t.

(thread-id)  ; => int

Since: Phase T19-C

defn

cancel-thread

(cancel-thread [t :ptr<void>])

request cooperative cancellation of a thread handle.

ta thread handle returned by thread-spawn-fn

:void

(let [t (thread-spawn-fn my-fn arg)]
    (cancel-thread t)
    (thread-join t))

Since: Phase TC0

defn

cancelled?

(cancelled?)

return true if the current thread has been cancelled.

bool -- true if a cancellation has been requested for this thread

(when (cancelled?) (cleanup-and-return))

Since: Phase TC0

defn

with-cancel-guard

(with-cancel-guard [cleanup :ptr<void> body :ptr<void>])

run a body closure; on cancellation, run cleanup and return nil.

cleanupzero-argument closure: (fn [] ...) to run on cancellation
bodyzero-argument closure: (fn [] ...) to run normally

:nil (always; body result is discarded)

(with-cancel-guard
    (fn [] (release resource))
    (fn []
      (let [v (chan-recv ch)]
        (process v))))

Since: Phase TC1

defmacro

yield-point

(yield-point)

check for a pending cancellation and exit if one is set.

:void (never returns if the thread has been cancelled)

(defn crunch [n] :int
    (let [i 0]
      (while (< i n)
        (yield-point)
        (do-work i)
        (set! i (+ i 1)))))

Since: Phase TC2

Internal definitions
__yield-point-impl-- internal: check cancel and exit if cancelled.