Module ThreadLocal

module ThreadLocal: sig .. end
Thread-local variables.

type 'a t = java'lang'ThreadLocal java_instance
The type of thread-local variables, providing an independent value to each thread.
 
val make : 'a -> 'a t
Returns a new thread-local variable whose initial value in each thread is the passed value; see ThreadLocal(...) and initialValue(...).
 
val get : 'a t -> 'a
Returns the value of the thread-local variable for the current thread; see get(...).
 
val remove : 'a t -> unit
Removes the value of the thread-local variable for the current thread. The variable can still be set or get. If no set occurs between remove and get, the variable is reinitialized with the value originally passed to make; see remove(...).
 
val set : 'a t -> 'a -> unit
Modifies the value of the thread-local variable for the current thread; see set(...).
 

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.