<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/stackless-coroutines-in-libdex-9vniovnm6" -->

---
title: Stackless Coroutines in Libdex | daily.dev
description: Christian Hergert introduces stackless coroutines as a new lightweight alternative to fibers in Libdex, a C async/futures library used in GNOME. Unlike fibers,...
canonical: https://daily.dev/posts/stackless-coroutines-in-libdex-9vniovnm6
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Stackless Coroutines in Libdex | daily.dev
og:description: Christian Hergert introduces stackless coroutines as a new lightweight alternative to fibers in Libdex, a C async/futures library used in GNOME. Unlike fibers,...
og:url: https://daily.dev/posts/stackless-coroutines-in-libdex-9vniovnm6
og:image: https://api.daily.dev/og/posts/9VniovNM6.png
og:image:alt: Stackless Coroutines in Libdex
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Stackless Coroutines in Libdex

**[Happenings in GNOME](https://daily.dev/sources/chergert)** · 3 min read · 0 upvotes · 0 comments

## Summary

Christian Hergert introduces stackless coroutines as a new lightweight alternative to fibers in Libdex, a C async/futures library used in GNOME. Unlike fibers, stackless coroutines don't require a separate stack or register saving, making them cheaper for simple future-coordinating work, though benchmarks show only modestly lower overhead than fibers. They integrate with DexFuture and DexTaskGroup, support cancellation, and use switch/case-based suspension (via DEX_COROUTINE_SUSPEND_* macros) to stay portable across compilers lacking address-of-label support, like MSVC and clang-cl. State must be kept in closure structs rather than on the stack, and helper macros like DEX_DEFINE_CLOSURE_TYPE simplify creating the needed boilerplate.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blogs.gnome.org/chergert/2026/06/08/stackless-coroutines-in-libdex>

## Questions this post answers

### What are stackless coroutines in Libdex and how do they differ from fibers?

Stackless coroutines are a new lightweight concurrency primitive added to Libdex that avoid the need for a separate stack or register saving, unlike fibers. They suspend and resume by re-entering the function and jumping to the next position via switch/case, reusing the calling thread's stack, with state saved in a closure struct instead. They can still be represented as a DexFuture and composed with fibers and threadpool work inside a DexTaskGroup, and benchmarks show somewhat lower overhead than fibers.

_Following async C patterns like Libdex's stackless coroutines is easier with daily.dev's developer feed._

### Why can't Libdex stackless coroutines use the same await syntax as fibers?

Stackless coroutines rely on switch/case jumps rather than direct stack manipulation to remain portable across Linux, Windows, FreeBSD, Solaris, and macOS, particularly because MSVC and clang-cl lack address-of-label support. This forces a different, more explicit suspend/resume syntax using DEX_COROUTINE_SUSPEND_* macros instead of the syntax fibers use for awaiting futures.

_Developers weighing portability tradeoffs in async C libraries can track changes like this via daily.dev._

### How do I define closure state for a Libdex stackless coroutine?

Use the DEX_DEFINE_CLOSURE_TYPE() macro, which generates the typedef struct along with matching _new() and _free() helper functions in one expansion. Fields are declared with helpers like DEX_DEFINE_CLOSURE_VALUE for plain values, DEX_DEFINE_CLOSURE_POINTER for pointers with a custom free function, and DEX_DEFINE_CLOSURE_OBJECT for GObject-based types, ensuring state survives across suspend points since it can't live on the stack.

_daily.dev helps C developers keep up with library-specific patterns like Libdex's closure macros._

## Similar posts on daily.dev

- [vittorio romeo's website](https://daily.dev/posts/vittorio-romeo-s-website-eqgqgk7vc) · Lobsters · 0 upvotes · 0 comments

---

Tags: [#linux](https://daily.dev/tags/linux), [#c](https://daily.dev/tags/c)

[View this post on daily.dev](https://daily.dev/posts/stackless-coroutines-in-libdex-9vniovnm6)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Stackless Coroutines in Libdex","url":"https://daily.dev/posts/stackless-coroutines-in-libdex-9vniovnm6","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/stackless-coroutines-in-libdex-9vniovnm6"},"datePublished":"2026-08-31T05:54:44.258Z","dateModified":"2026-08-31T05:56:34.616Z","description":"Christian Hergert introduces stackless coroutines as a new lightweight alternative to fibers in Libdex, a C async/futures library used in GNOME. Unlike fibers,...","image":"https://media.daily.dev/image/upload/s--qPvKM23u--/f_auto/v1722860399/public/Placeholder%2009","thumbnailUrl":"https://media.daily.dev/image/upload/s--qPvKM23u--/f_auto/v1722860399/public/Placeholder%2009","isAccessibleForFree":true,"articleSection":"Happenings in GNOME","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Happenings in GNOME","logo":"https://media.daily.dev/image/upload/logos/placeholder.jpg","url":"https://daily.dev/sources/chergert"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/stackless-coroutines-in-libdex-9vniovnm6","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"linux,c","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Happenings in GNOME","item":"https://daily.dev/sources/chergert"},{"@type":"ListItem","position":3,"name":"Stackless Coroutines in Libdex"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/stackless-coroutines-in-libdex-9vniovnm6#faq","mainEntity":[{"@type":"Question","name":"What are stackless coroutines in Libdex and how do they differ from fibers?","acceptedAnswer":{"@type":"Answer","text":"Stackless coroutines are a new lightweight concurrency primitive added to Libdex that avoid the need for a separate stack or register saving, unlike fibers. They suspend and resume by re-entering the function and jumping to the next position via switch/case, reusing the calling thread's stack, with state saved in a closure struct instead. They can still be represented as a DexFuture and composed with fibers and threadpool work inside a DexTaskGroup, and benchmarks show somewhat lower overhead than fibers. Following async C patterns like Libdex's stackless coroutines is easier with daily.dev's developer feed."}},{"@type":"Question","name":"Why can't Libdex stackless coroutines use the same await syntax as fibers?","acceptedAnswer":{"@type":"Answer","text":"Stackless coroutines rely on switch/case jumps rather than direct stack manipulation to remain portable across Linux, Windows, FreeBSD, Solaris, and macOS, particularly because MSVC and clang-cl lack address-of-label support. This forces a different, more explicit suspend/resume syntax using DEX_COROUTINE_SUSPEND_* macros instead of the syntax fibers use for awaiting futures. Developers weighing portability tradeoffs in async C libraries can track changes like this via daily.dev."}},{"@type":"Question","name":"How do I define closure state for a Libdex stackless coroutine?","acceptedAnswer":{"@type":"Answer","text":"Use the DEX_DEFINE_CLOSURE_TYPE() macro, which generates the typedef struct along with matching _new() and _free() helper functions in one expansion. Fields are declared with helpers like DEX_DEFINE_CLOSURE_VALUE for plain values, DEX_DEFINE_CLOSURE_POINTER for pointers with a custom free function, and DEX_DEFINE_CLOSURE_OBJECT for GObject-based types, ensuring state survives across suspend points since it can't live on the stack. daily.dev helps C developers keep up with library-specific patterns like Libdex's closure macros."}}]}
```

