Don't automatically unlock/lock I/O channels managed from C#11356
Don't automatically unlock/lock I/O channels managed from C#11356xavierleroy merged 2 commits intoocaml:trunkfrom
Conversation
… locked Channels allocated from C are entirely managed by the C code, including locking and unlocking, so no automatic unlock/lock should take place. Currently, all channels allocated from C are used in a single-threaded manner and don't need to be locked. However, they need to be locked in advance to avoid run-time errors when unlocking in check_pending. This is unpleasant and a source of potential errors: locking also sets the last_channel_locked state component, causing surprise unlocks when an exception is raised from C.
They are used in a single-threaded manner.
|
Apropos damiendoligez#7 (comment), I grep'd opam for
I also grep'd for the At least from opam-repository, I'd tentatively conclude that the C interface for channels is not used much (it's also guarded by |
Thanks for having checked. Quoting from the discussion on the other PR:
It's the change in 4.12 that could have broken other libraries, by forcing them to add Lock/Unlock operations even for single-threaded usage. The change in this PR can only "un-break" these libraries. |
They are used in a single-threaded manner. Locking is no longer necessary since ocaml#11356. Also remove the recently-added caml_channel_reset_last_locked() function which is no longer needed.
|
Cherry-picked to 5.0 : 34b694d |
Don't automatically unlock/lock I/O channels managed from C (cherry picked from commit 9f4e887)
I/O channels allocated from C are entirely managed by the C code, including locking and unlocking, so no automatic unlock/lock should take place in
check_pending.Currently, all channels allocated from C are used in a single-threaded manner and don't need to be locked. However, they need to be locked in advance to avoid run-time errors when unlocking in check_pending. This is unpleasant and a source of potential errors, as in #11065 .
This PR turns off the unlock/lock dance in
check_pendingfor channels allocated from C. I don't think there's any adverse effect since these channels are not accessible to OCaml code that could be run by finalizers or signal handlers. As a consequence we can remove a fewLock/Unlockpairs that were introduced just to pleasecheck_pending.Cc: @damiendoligez @sadiqj @stedolan