No matching definitions.

tur/fiber

stdlib/fiber.tur

lightweight cooperative fibers backed by the FiberBlock runtime.

Since: Phase T21-C

defn

fiber-new

(fiber-new [fn :ptr<void> stack-size :int] :ptr<void>)

create a new fiber from a function pointer and an optional stack size.

fnzero-argument function pointer to run as the fiber body
stack-sizerequested stack size in bytes; 0 uses the default size

An opaque ptr<void> handle to the FiberBlock.

(let [f (fiber-new my-fn 0)] ...)  ; => ptr<void>

Since: Phase T21-C

defn

fiber-resume

(fiber-resume [f :ptr<void> arg :int] :int)

resume a suspended fiber, passing it a value, and return the yielded or final value.

ffiber handle returned by fiber-new
argvalue passed to the fiber as the resume argument

The int64_t value yielded by the fiber, or its final return value.

(fiber-resume f 0)  ; => int

Since: Phase T21-C

defn

fiber-yield

(fiber-yield [value :int] :nil)

suspend the current fiber and return a value to its caller.

valueint64_t value to hand back to the fiber-resume caller
(fiber-yield 42)

Since: Phase T21-C

defn

fiber-done?

(fiber-done? [f :ptr<void>] :int)

check whether a fiber has run to completion.

ffiber handle returned by fiber-new

Non-zero (truthy) if the fiber has returned; 0 if it is still runnable or suspended.

(if (fiber-done? f) ...)  ; => int

Since: Phase T21-C

defn

fiber-arg

(fiber-arg [f :ptr<void>] :int)

retrieve the most recent argument value passed to a fiber via fiber-resume.

ffiber handle returned by fiber-new

The int64_t argument last supplied to fiber-resume, or 0 if the handle is NULL.

(fiber-arg f)  ; => int

Since: Phase T21-C

defn

fiber-free

(fiber-free [f :ptr<void>] :nil)

release all memory associated with a fiber.

ffiber handle returned by fiber-new
(fiber-free f)

Since: Phase T21-C

defn

fiber-local-get

(fiber-local-get [f :ptr<void> key :int] :int)

retrieve a fiber-local value by key from a specific fiber.

ffiber handle returned by fiber-new
keyint64_t key identifying the slot

The int64_t value stored at key, or 0 if not set.

(fiber-local-get f 1)  ; => int

Since: Phase T21

defn

fiber-local-set!

(fiber-local-set! [f :ptr<void> key :int value :int] :nil)

store a fiber-local value by key in a specific fiber.

ffiber handle returned by fiber-new
keyint64_t key identifying the slot
valueint64_t value to store
(fiber-local-set! f 1 99)

Since: Phase T21

defn

fiber-local-current-get

(fiber-local-current-get [key :int] :int)

retrieve a fiber-local value by key from the currently running fiber.

keyint64_t key identifying the slot

The int64_t value stored at key in the current fiber, or 0 if not set.

(fiber-local-current-get 1)  ; => int

Since: Phase T21

defn

fiber-local-current-set!

(fiber-local-current-set! [key :int value :int] :nil)

store a fiber-local value by key in the currently running fiber.

keyint64_t key identifying the slot
valueint64_t value to store
(fiber-local-current-set! 1 99)

Since: Phase T21

defn

scheduler-yield!

(scheduler-yield! :nil)

yield the current fiber back to the scheduler, re-enqueueing it for the next turn.

(scheduler-yield!)

Since: Phase T21

defn

scheduler-park!

(scheduler-park! :nil)

park the current fiber, suspending it without re-enqueueing.

(scheduler-park!)

Since: Phase T21

defn

scheduler-unpark!

(scheduler-unpark! [f :ptr<void>] :nil)

unpark a specific fiber and add it back to the scheduler run queue.

ffiber handle to unpark
(scheduler-unpark! f)

Since: Phase T21

defn

async-sleep

(async-sleep [ms :int] :nil)

sleep for approximately ms milliseconds without blocking the OS thread.

msduration in milliseconds; values <= 0 return immediately
(async-sleep 100)

Since: Phase T24

defn

fiber-thread-id

(fiber-thread-id :int)

return an integer identifier for the OS thread running the current fiber.

The current pthread_t cast to int64_t.

(fiber-thread-id)  ; => int

Since: Phase T23