facebookexperimental / facebookexperimental/libunifex
Is there something equivalent to thread-local storage, but for coroutines?
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 210
- PR merge metrics
- No merged PRs in 30d
Description
Let's call it something like `LocalContext` for now. And let's make the simplification we're dealing with a `unifex::task`.
The basic requirements I am looking for are:
1. When 2 unrelated tasks interleave on the same executor, their `LocalContext`s are isolated from one another.
2. When there's a parent-child relationship between 2 tasks (e.g. taskA `co_await`s on `taskB`), taskA's context is propagated onto `taskB`'s contexts.
3. `LocalContext`s resources are managed by the containing tasks (i.e. they get destroyed when the underlying coroutine gets destroyed).
Python has [ContextVars](https://docs.python.org/3/library/contextvars.html) that is more or less what I describe above. It has the added advantage that it works also in cases where you need plain thread local storage.
I did a little bit of search some time ago, but didn't see anything in the works or being proposed.
Contributor guide
Assessment
This issue has not been assessed yet.