facebookexperimental / facebookexperimental/libunifex
at_coroutine_exit can probably break scheduler affinity
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 210
- PR merge metrics
- No merged PRs in 30d
Description
I can't _know_ without writing a unit test, but I'm pretty certain this breaks _Scheduler_ affinity:
```
template
task foo(Scheduler someOtherScheduler) {
co_await at_coroutine_exit([=]() noexcept {
return schedule(someOtherScheduler);
});
}
```
There's no infrastructure in the implementation of `at_coroutine_exit` to prevent the above from breaking the affinity invariant and no tests confirming that it _doesn't_ break the invariant so it's almost certainly broken.
Note: the magic behaviour of `co_await schedule(s);` in a coroutine _maintains_ the affinity invariant by using `at_coroutine_exit` to reschedule onto the _correct_ _Scheduler_ so fixing this will require some careful thought.
Contributor guide
Assessment
This issue has not been assessed yet.