add missing CAMLparam in caml_ml_close_channel#12436
add missing CAMLparam in caml_ml_close_channel#12436damiendoligez wants to merge 1 commit intoocaml:trunkfrom
Conversation
|
Is there a similar issue in |
|
Note that the bug was already a bug in OCaml 4; your explanation is in terms of domains but (non-parallel) threads can create the same problems. Random remark: another way to keep a channel alive is to increase its refcount before and decrement it after the work has been done. I think that simply registering the root as proposed is a much better approach, of course. As @yallop I started looking for other instances of related bugs in io.c. I suspect that there may be several others, for example:
Basically it looks like we should always root the channel argument for safety reasons, and justify with a comment the rare cases where we intentionally decide not to. |
|
I propose a more systematic approach in #12445 which adds roots to many more functions. |
|
|
|
|
||
| CAMLprim value caml_ml_close_channel(value vchannel) | ||
| { | ||
| CAMLparam1 (vchannel); |
There was a problem hiding this comment.
I think it’s worth a comment about the need for the root, given how subtle the trigger is!
There was a problem hiding this comment.
Your proposal works well within the mindset that registering roots should be avoided unless necessary -- here we cannot avoid it for a subtle reason, so we should document it.
I think that we should think differently, and reflect this in our documentation practices: we should not require justification for registering values (the easy and safe thing), we should require justification for not registering values (the subtle and unsafe thing).
I don't know enough about the OCaml 5 GC to agree or disagree with this. However, if you have multiple threads, both in OCaml 4 and in OCaml 5, |
|
Ah, I see (and I'd failed to see that @yallop had said that too) - the domain lock may be released in |
|
Superseded by #12445, which is now merged. |
This fixes a random crash, which is made much more probable by a future PR of mine.
The crash is as follows:
pthread_mutex_destroyon a mutex that's still locked and triggers a fatal error.The fix is to keep the channel alive until it's unlocked.