[ocaml-ctypes] Lifecycle of a callback?
Daniel Bünzli
daniel.buenzli at erratique.ch
Tue Oct 21 14:14:52 BST 2014
Le mardi, 21 octobre 2014 à 14:24, Trevor Smith a écrit :
> In the libuv bindings I am working on there is need for user callbacks. A user registers the callback with a function, and then at an arbitrary point in time later, the callback code is actually ran (started when the user starts the libuv event loop). I had naively thought that I would need to keep a reference to the user callback and then release this reference after the user callback was actually called (because the callback would be used at an arbitrary point in the future and could get gc'd).
This doesn't answer you question but just another thing to think about, if the callbacks may occur on another thread you should also be careful on acquiring OCaml's runtime lock see for example here:
https://github.com/dbuenzli/tsdl/issues/13
I don't know if the support Jeremy mentions in that discussion was eventually merged in a published version since ctypes's release notes are a little bit hard to track down.
Best,
Daniel
P.S. Just one comment dont do `let _ = ...` you will soon or later loose a lot of time because you only partially applied a function while you thought the application was total. Use `let () = ...` and use `ignore` if you need to ignore a result — and sequencing with ; is fine too.
More information about the Ctypes
mailing list