Any way to get a pointer to the stack frame?

I’m watching this talk (CppCon 2015: Pablo Halpern “Work Stealing") and at one point they talk about continuation stealing which involves having a function continue execution on a different thread. Any way to replicate this in Odin?

you have the task that just finished push the “continuation” as a task into the work queue just as if it was a synchronous completion callback that scheduled another task based on the result

1 Like

That’s the workaround I’m planning to use but then you couldn’t use the stack memory to ‘continue’, instead you’d have to allocate memory somewhere and access it in the continuation callback.

I could push that burden on to the library user to just use their own allocator but parallel programming is confusing enough and ideally the library would make that easier.

I’m thinking I should have a fixed amount of memory pages which a thread can acquire to allocate into. The library could then provide an allocator for a task, track when tasks and their children finish, and then free any memory associated with the task.

Doing this tracking would add additional overhead even though the memory is all preallocated, and would make the api more complex, plus it would make it more magical and abstract.

Continuation stealing is magical as well but there is less going on under the hood. I was just wondering if there was a way to avoid all the complexity. It’s fine though, I’ll just go with the alternative architecture.

there’s a bigger issue, as soon as a function returns then the stack frame’s memory is free to get reused.

So the memory has to live outside the space of the function-local variables.

I thought that’s what I was talking about. Or am I misunderstanding what you’re talking about? If this is in regards to continuation stealing, then it shouldn’t be an issue since the sync point exists before the function returns (even if not added explicitly), and the last thread to reach the sync point continues afterwards in a single threaded fashion while the other stops executing the function and does something else. I’m sure there is lot of complexity there that I don’t realize though.