-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Synchronization of refcount fields in bigarray.h/io.h #10832
Description
As per #10831, this concerns the multicore PR and is opened as a separate issue from the PR.
The refcount fields in caml/{bigarray,io}.h perform reference counting for values that may or may not be shared across threads (with or without appropriate synchronisation by the user during their use). The one in io.h was made atomic, but the one in bigarray.h was not. I think that atomic refcounting is needed both for memory safety (hence MVP) and because programmers would not be able to implement their own synchronisation mechanism since they do not control when finalizers run.
It might be worth it to factorize in a helper header the code needed to implement refcounted finalizers in io.h/bigarray.h. As a post-MVP feature suggestion, I think that refcounted finalizers for similarly-shared resources can be useful to programmers, because atomic refcounting is delicate to implement correctly in an optimized fashion (with a bonus question: does the OCaml memory model change anything to the usual optimized implementation?).