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:
The local allocator is thread-safe by design. Thanks Immix.
The global allocator must use mutexes whenever it mutates memory or iterates mutable data;
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.
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.