ysbaddaden / gc

A garbage collector for Crystal
95 stars 6 forks source link

Thread safety #7

Closed ysbaddaden closed 2 years ago

ysbaddaden commented 6 years ago

For now the allocator and collector assume that crystal programs are single threaded. Since Crystal aims to be multithreaded, we must make it's internal design thread safe:

Furthermore GC_collect should send a signal to all threads, telling them to immediately save its running fiber context (i.e. CPU registers) to the fiber stack, then sleep. Once all threads have been stopped, the collector will start. When done, the collector will wake up all pending threads to pick the paused fiber, restore its context from the stack and resume execution.

ysbaddaden commented 2 years ago

Protecting the allocators ain't very hard.

Stopping the world... is a whole another matter.

ysbaddaden commented 2 years ago

Stop the world will be tackled in its own issue: #20