HNHacker News
TopNewBestAskShowJobs

zerotonine

2 karma · joined January 13, 2020

submissionscomments
zerotonine··on How to Allocate Memory (2016)
Can anyone think of a use case for creating a second stack, without a thread, to allocate memory? The approach I have in mind: 1) Create a new stack POSIX makecontext() w/ initializer thread. 2) Initializer thread makes function calls to allocate objects. Functions are called in sequence and never return. The thread eventually reaches the end of its initialization sequence and stalls. 3) Use swapcontext() to return to the original thread from #1. 4) Original thread may reference all objects allocated on the stack of the other context.

This seems like a widget that could be used to accomplish something interesting, but I'm not sure what that might be.