Module Exchanger

module Exchanger: sig .. end
Value exchangers.

type 'a t = java'util'concurrent'Exchanger java_instance
The type of exchangers, allowing two threads to swap values.
 
val make : unit -> 'a t
Returns a new exchanger; see Exchanger(...).
 
val exchange : 'a t -> 'a -> 'a
Waits for another thread to arrive at the same exchange point, and then swaps the values provided by the two threads; see exchange(...).
Raises Java_exception if the thread is interrupted
 
val exchange_time : 'a t -> 'a -> java_long -> TimeUnit.t -> 'a
exchange_time e x t u is similar to exchange e x, except that the current thread will at most wait for t (time value whose unit is u); see exchange(...).
Raises
  • Java_exception if the thread is interrupted
  • Java_exception if time has elapsed with no exchange
 

Null value

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

Miscellaneous

 
val wrap : 'a t -> 'a 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 : 'a t option -> 'a t
unwrap obj unwraps the option obj into a bare reference:
  • Some x is mapped to x;
  • None is mapped to null.