diff --git a/src/threads/CCSemaphore.ml b/src/threads/CCSemaphore.ml index 22673dfd..17d0b6de 100644 --- a/src/threads/CCSemaphore.ml +++ b/src/threads/CCSemaphore.ml @@ -6,11 +6,12 @@ type t = { cond : Condition.t; } -let create n = { - n; - mutex=Mutex.create(); - cond=Condition.create(); -} +let create n = + if n <= 0 then invalid_arg "Semaphore.create"; + { n; + mutex=Mutex.create(); + cond=Condition.create(); + } let get t = t.n diff --git a/src/threads/CCSemaphore.mli b/src/threads/CCSemaphore.mli index 7f8c9ad6..5734d31c 100644 --- a/src/threads/CCSemaphore.mli +++ b/src/threads/CCSemaphore.mli @@ -9,13 +9,13 @@ type t val create : int -> t (** [create n] creates a semaphore with initial value [n] - @raise Invalid_argument if [n < 0] *) + @raise Invalid_argument if [n <= 0] *) val get : t -> int (** Current value *) val acquire : int -> t -> unit -(** [acquire n s] blocks until [get s > n], then atomically +(** [acquire n s] blocks until [get s >= n], then atomically sets [s := !s - n] *) val release : int -> t -> unit