Discussion:
[Gc] GC and Coroutines in multiple threads
Juan Wajnerman
2015-09-22 03:24:27 UTC
Permalink
Long time ago, I opened a discussion about using the GC with coroutines (using libpcl): https://lists.opendylan.org/pipermail/bdwgc/2014-January/005819.html


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).


Best regards!
- Juan
Ivan Maidanski
2015-09-23 08:22:15 UTC
Permalink
My current understanding is that fiber/coroutine is similar to regular thread except that we are in do-blocking state for all except current fiber.
It is better to propose high level api for fibers like register/unregister/switchTo or even intercept system fiber api like we did for regular threads.
Long time ago, I opened a discussion about using the GC with coroutines (using libpcl):  https://lists.opendylan.org/pipermail/bdwgc/2014-January/005819.html
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).
Best regards!
- Juan
_______________________________________________
bdwgc mailing list
https://lists.opendylan.org/mailman/listinfo/bdwgc
Loading...