Skip to content

Conversation

@redianthus
Copy link
Member

@redianthus redianthus commented Dec 12, 2025

cc @krtab

There was a bug here: https://github.com/OCamlPro/synchronizer/pull/5/changes#r2614774996

I also added a Fun.protect in work_while to make sure the pledge is ended even if the function fails. Other changes are simply cleaning.

let get ?(pledge = true) synchro =
let rec inner_loop pledge synchro =
match synchro.getter () with
| None when synchro.pledges = 0 || synchro.closed ->
Copy link
Member Author

@redianthus redianthus Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was wrong @krtab. It may have been that you parsed it as:

    | (None when synchro.pledges = 0) || (synchro.closed) ->

Whereas it is really:

   | None when ((synchro.pledges = 0) || (synchro.closed)) ->

It means that if the synchronizer was closed but nonempty, then we would still return stuff from it, leading to a lot of unexpected behaviors...

The fix is to check if the synchronizer was closed first without looking at if it is empty or not.

@redianthus redianthus force-pushed the deadlock branch 2 times, most recently from 8f0603b to b26ae63 Compare December 12, 2025 16:48
`end_plege` is called in `work_while` when the function fails
@redianthus redianthus changed the title fix deadlock and small optimization to broadcast out of the mutex lock fix a bug when the synchronizer was closed but still has some elements Dec 12, 2025
@redianthus redianthus changed the title fix a bug when the synchronizer was closed but still has some elements fix a bug when the synchronizer was closed but still has some elements and one where we would not end a pledge in case of failure Dec 12, 2025
@redianthus redianthus merged commit cebe779 into main Dec 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants