3 ms·
This can be implemented without assembly using setcontext/getcontext on POSIX-compatible systems, and GetThreadContext/SetThreadContext on Windows.
by nanofortnight 13y ago
This can be implemented without assembly using setcontext/getcontext on POSIX-compatible systems, and GetThreadContext/SetThreadContext on Windows.
- cygx 13y agoNot if you care for performance.
- nanofortnight 13y agoget/setcontext do not copy stack, but use an allocated bit of memory space for the stack and swaps stack pointers just like this implementation. I don't see how that's a performance hit. I do not pretend to know about Windows internals so I won't comment on Windows.
- vinkelhake 13y agoThe author of boost.context did some benchmarking[1] and found that get/setcontext was an order of magnitude slower than a custom solution. Whether this matters is an entirely different question, but it's clear that get/setcontext has some overhead. [1] http://www.boost.org/doc/libs/1_54_0/libs/context/doc/html/context/performance.html http://www.boost.org/doc/libs/1_54_0/libs/context/doc/html/c...
- cygx 13y agoSee also the notes on various implementation mechanisms of libcoro ( http://cvs.schmorp.de/libcoro/coro.h http://cvs.schmorp.de/libcoro/coro.h )
- davidtgoldblatt 13y agogetcontext and setcontext also keep track of signal state, which involves a syscall.
- anon1385 13y agoExamples of that in the Io source: https://github.com/stevedekorte/io/blob/master/libs/coroutine/source/Coro.c https://github.com/stevedekorte/io/blob/master/libs/coroutin... https://github.com/stevedekorte/io/blob/master/libs/coroutine/source/context.c https://github.com/stevedekorte/io/blob/master/libs/coroutin...