4 ms·
This abstraction that a heap is somehow different than stack is hurting understanding; they're just regions of memory. Go stacks are allocated areas of memory
by yencabulator 2y ago
This abstraction that a heap is somehow different than stack is hurting understanding; they're just regions of memory.
Go stacks are allocated areas of memory like anything else. When a green thread is suspended, it's stack is not "serialized to the heap". Switching green threads is mostly a question of setting the stack pointer to point to the new green thread's stack.
What makes threads "green" is that they are not supposed to call blocking syscalls (they can queue work in a separate blocking threadpool and call the scheduler to suspend themselves). Go has a signal-based mechanism for non-cooperative scheduling of green threads, so green threads are not even required to cooperatively yield to the scheduler.