ocamllabs / ocaml-effects

*DEPRECATED: See ocaml-multicore/ocaml-multicore* OCaml effects handlers
Other
27 stars 4 forks source link

Callbacks should run on the parent OCaml stack #7

Closed kayceesrk closed 8 years ago

kayceesrk commented 8 years ago

The current design for OCaml callbacks from C in the new native code backend is unsatisfactory. In particular, OCaml callbacks run on a fresh stack, and not the stack of the parent OCaml function (if one exists). This isn't a problem usually, but it turns out to be very bad for timer interrupts. Every time a timer interrupt is handled, a new OCaml stack is created on the heap and discarded soon after.

There are two options to make this better. (1) Hang onto the callback stack instead of discarding it. The signal handler instances reuse the stack (2) Use the stack of the parent OCaml function. This solution is closer to the vanilla implementation. I am tempted to implement (2) since (1) involves more bookkeeping. But (2) also gets us closer to an implementation where the main OCaml function runs on the C stack.