Previous Up Next

Module Semaphore

module Semaphore: sig .. end
Semaphores.

type t = java'util'concurrent'Semaphore java_instance
The type of semaphores, each maintaining a set of available permits.
val make : ?fair:bool -> java_int -> t
make ~fair:f p returns a new semaphore with p permits, f indicating whether a fair ordering policy is requested (defaulting to false); see Semaphore(...) .

p can be negative, meaning that permits should be released before any acquisition.
val acquire : t -> java_int -> unit
acquire s p acquires p permits from semaphore s, blocking until they are available; see acquire(...) .
Raises
  • Java_exception if p is negative
  • Java_exception if the thread is interrupted
val acquire_uninterruptibly : t -> java_int -> unit
acquire_uninterruptibly s p is similar to acquire s p, except that waiting thread cannot be interrupted; see acquireUninterruptibly(...) .
Raises Java_exception if p is negative
val available_permits : t -> java_int
Returns the number of available permits for the semaphore; see availablePermits(...) .
val drain_permits : t -> java_int
Acquires and returns all available permits from the semaphore, returning immediately; see drainPermits(...) .
val get_queue_length : t -> java_int
Returns an estimate of the number of threads waiting on the semaphore to acquire permits; see getQueueLength(...) .
val has_queued_threads : t -> bool
Tests whether there are threads waiting on the semaphore to acquire permits; see hasQueuedThreads(...) .
val is_fair : t -> bool
Tests whether the semaphore uses a fair policy; see isFair(...) .
val release : t -> java_int -> unit
release s p releases p permits from semaphore s; see release(...) .
Raises Java_exception if p is negative
val try_acquire : t -> java_int -> bool
try_acquire s p is similar to acquire s p, except the function always returns immediately returning true if acquisition was successful; see tryAcquire(...) .
Raises Java_exception if p is negative
val try_acquire_time : t -> java_int -> java_long -> TimeUnit.t -> bool
try_acquire_time s p t u is similar to try_acquire s p, except that the current thread will at most wait for t (time value whose unit is u); see tryAcquire(...) .
Raises
  • Java_exception if p is negative
  • Java_exception if the thread is interrupted

Null value

val null : t
The null value.
val is_null : t -> bool
is_null obj returns true iff obj is equal to null.
val is_not_null : t -> bool
is_not_null obj returns false iff obj is equal to null.

Miscellaneous

val wrap : t -> t option
wrap obj wraps the reference obj into an option type:
  • Some x if obj is not null;
  • None if obj is null.

val unwrap : t option -> t
unwrap obj unwraps the option obj into a bare reference:
  • Some x is mapped to x;
  • None is mapped to null.

AltStyle によって変換されたページ (->オリジナル) /