Main thread context returning in a different hardware thread, undefined behaviour?

71 views Asked by At

I'm currently working on a concurrency library for C++ with green threads using work stealing for load balancing between schedulers on multiple hardware threads.

I've pinned the main context to its hardware thread, meaning it cannot be stolen and therefore migrate to other hardware threads.

I believe I've read this somewhere that if the main context where to be stolen and return (exit) in different hardware thread from where it originated from it is undefined behaviour. But, I cannot seem to find any sources on this now.

Is this undefined behaviour? Citing sources would be perfect.

1

There are 1 answers

0
Alexey Guseynov On

First of all, there are no green threads in standard C++. So the whole thing with making your own stacks and replacing them is undefined behaviour. UB doesn't mean that something will not work. It means that there is no guarantee that it will work on any standard compliant system.

Green threads/coroutines are balancing on the edge of UB, making implementation for every supported platform. They work bacause they were written for specific platforms and have kludges to overcome diferent pitfals on these platforms.