Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] How to register a struct of values with the GC so they remain accessible without runtime lock?
@ 2016-03-07  3:00 Goswin von Brederlow
  0 siblings, 0 replies; only message in thread
From: Goswin von Brederlow @ 2016-03-07  3:00 UTC (permalink / raw)
  To: Ocaml Mailing List

Hi,

for my Qt5 bindings I need to keep track of any number of ocaml values
for a Qt5 class. I could allocate a block on the ocaml heap to store
all those values, store the address of that with the Qt5 class and
register it as global root. But then any access would require aquiring
the ocaml runtime lock.

A bunch of values are closures for optional callbacks, with a value of
0 denoting the callback isn't installed. I would like to at least
check values against 0, in which case I can just go back to Qt5
without having to wait for the runtime lock. I imagine having to wait
for the ocaml runtime lock would seriously impact the responsiveness
of the GUI since a number of callbacks get invoked for any action,
like moving the mouse from one widget to another. (Assuming some other
ocaml threads are running and stealing the lock inbetween callbacks.)
If they are not 0 then I would aquire the runtime lock, read the value
again and call the calback.

I could do this by registering every single field of the structure as
global root separatly.

1) Is that actually save? When moving values the GC will never set a
closure value to 0 temporarily, right?

2) Would that be insane? A normal GUI could have thousands of roots
then but they would never (rarely) change [could use generational
roots].

3) Is there a better way?

MfG
	Goswin

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-03-07  3:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-07  3:00 [Caml-list] How to register a struct of values with the GC so they remain accessible without runtime lock? Goswin von Brederlow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox