Class (GI Class)

Dex-1DexThreadPoolScheduler

Dex.ThreadPoolScheduler is a Dex.Scheduler that will dispatch work items and fibers to sub-schedulers on a specific operating system thread.

Dex.Fiber will never migrate from the thread they are created on to reduce chances of safety issues involved in tracking state between CPU.

New work items are placed into a global work queue and then dispatched efficiently to a single thread pool worker using a specialized async semaphore. On modern Linux using io_uring, this wakes up a single worker thread and therefore is not subject to "thundering herd" common with global work queues.

When a worker creates a new work item, it is placed into a work stealing queue owned by the thread. Other worker threads may steal work items when they have exhausted their own work queue.

Hierarchy (View Summary)

Index

Constructors

Properties

Methods

  • Gets the default thread pool scheduler for the instance.

    This function is useful to allow programs and libraries to share an off-main-thread scheduler without having to coordinate on where the scheduler instance is created or owned.

    Returns Dex.Scheduler

Methods - Inherited from Dex.Scheduler

  • Request scheduler to spawn a Dex.Fiber.

    The fiber will have its own stack and cooperatively schedules among other fibers sharing the scheduler.

    If stack_size is 0, it will set to a sensible default. Otherwise, it is rounded up to the nearest page size.

    static DexFuture *
    fiber_func (gpointer data)
    {
    GInputStream *stream = data;
    g_autoptr(GError) error = NULL;
    g_autoptr(GBytes) bytes = NULL;

    if (!(bytes = dex_await_boxed (dex_input_stream_read_bytes (stream, 4096, 0), &error)))
    return dex_future_new_for_error (g_steal_pointer (&error));

    ...

    return dex_future_new_true ();
    }

    DexFuture *
    spawn_fiber (GInputStream *stream)
    {
    return dex_scheduler_spawn (NULL, 0, fiber_func,
    g_object_ref (stream),
    g_object_unref);
    }

    Parameters

    Returns Dex.Future

    a Dex.Future that will resolve or reject when func completes (or its resulting Dex.Future completes).

  • Releases a reference on the given object, and decreases its reference count by one.

    If it was the last reference, the resources associated to the instance are freed.

    Returns void

Interfaces

SignalSignatures