2015-09-22 03:24:27 UTC
Eventually I solved the problem, by setting GC_stackbottom to the right value before jumping to a different coroutine, and then making sure all coroutine stacks are visited during GC. The code is in Crystal language but I think itâs easy to understand even if you donât know the language:Â https://github.com/manastech/crystal/blob/master/src/fiber/fiber.cr
This works perfectly fine as long as a single thread is used, but now we want to to take this to the next level and have coroutines in multiple threads.
As far as I understand, GC_stackbottom only serves for the main thread. For other threads, this value is stored in GC_thread.stack_end. However this is not part of the public API. The only public function that can actually make changes to this value seems to be GC_call_with_gc_active. However, this is not useful for coroutines, because I need to set back the value once the coroutine is resumed, so this doesnât work with the callback style that this API have to offer.
Do you think itâs possible to add some public API to expose this functionality? I could work on this and send a PR. For example, adding a function like: GC_set_current_thread_stack_end(ptr_t).