Skip to content

Commit

Permalink
Fix with_acquire: release a non locked mutex is UB
Browse files Browse the repository at this point in the history
This is segfaulting (on ubuntu 16.04 and 16.10) when trying to release the unlocked mutex in the release stage (in general this is an undefined behavior).
  • Loading branch information
mseri authored and c-cube committed Jan 24, 2017
1 parent 56462a8 commit 59208fd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/threads/CCSemaphore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ let release m t =
*)

let with_acquire ~n t ~f =
Mutex.lock t.mutex;
acquire_once_locked_ n t;
acquire n t;
try
let x = f() in
release_once_locked_ n t;
release n t;
x
with e ->
release_once_locked_ n t;
release n t;
raise e

(*$R
Expand Down

0 comments on commit 59208fd

Please sign in to comment.