Module Thread

module Thread: sig .. end
Threads.

type state =
|  New (*The thread has not been started.*)
|  Runnable (*The thread is executing.*)
|  Blocked (*The thread is blocked on a lock.*)
|  Waiting (*The thread is waiting for another thread (with no timeout).*)
|  Timed_waiting (*The thread is waiting for another thread (with a timeout).*)
|  Terminated (*The thread has terminated execution.*)
The type of thread states; see java.lang.Thread.State.
 
val max_priority : java_int
The maximum priority for a thread; see java.lang.Thread#MAX_PRIORITY.
 
val min_priority : java_int
The minimum priority for a thread; see java.lang.Thread#MIN_PRIORITY.
 
val norm_priority : java_int
The normal (i. e. default) priority for a thread; see java.lang.Thread#NORM_PRIORITY.
 
type t = java'lang'Thread java_instance
The type of threads. If a thread raises an exception escapes, it is written to the standard output and then discarded.
 
val make : ?group:ThreadGroup.t -> ?name:JavaString.t -> ('a -> unit) -> 'a -> t
make g n f x returns a new thread in group g with name n. The thread will execute f x when started; see Thread(...).
 
val current_thread : unit -> t
Returns the thread that is currently executing; see currentThread(...).
 
val get_id : t -> java_long
Returns the thread identifier. The identifier is positive, and guaranteed to be unique while the thread is executing. The identifier can be recycled when the thread has terminated its execution; see getId(...).
 
val get_name : t -> JavaString.t
Returns the name of the thread; see getName(...).
 
val get_priority : t -> java_int
Returns the priority of the thread; see getPriority(...).
 
val get_state : t -> state
Returns the state of the thread; see getState(...).
 
val get_thread_group : t -> ThreadGroup.t
Returns the group of the thread, None if the thread has terminated its execution; see getThreadGroup(...).
 
val interrupt : t -> unit
Interrupts the thread; see interrupt(...).
 
val interrupted : unit -> bool
Tests whether the current thread has been interrupted, and sets its interrupted status to false; see interrupted(...).
 
val is_alive : t -> bool
Tests whether the thread has started and not terminated; see isAlive(...).
 
val is_daemon : t -> bool
Tests whether the thread is a daemon one; see isDaemon(...).
 
val is_interrupted : t -> bool
Tests whether the thread has been interrupted; see isInterrupted(...).
 
val join : t -> unit
Waits for the termination of the passed thread; see join(...).
Raises Java_exception if the thread is interrupted
 
val join_time : t -> java_long -> unit
join_time t m is similar to join t, except that the current thread will at most wait for m milliseconds; see join(...).
Raises
  • Java_exception if m is invalid
  • Java_exception if the thread is interrupted
 
val join_time_nanos : t -> java_long -> java_int -> unit
join_time t m n is similar to join t, except that the current thread will at most wait for m milliseconds plus n nanoseconds; see join(...).
Raises
  • Java_exception if m or n is invalid
  • Java_exception if the thread is interrupted
 
val set_daemon : t -> bool -> unit
Changes the daemon status of the thread; see setDaemon(...).
Raises Java_exception if the thread has already been started
 
val set_name : t -> JavaString.t -> unit
Changes the name of the thread; see setName(...).
 
val set_priority : t -> java_int -> unit
Changes the priority of the thread; see setPriority(...).
Raises Java_exception if the priority is invalid
 
val sleep : java_long -> unit
sleep m waits for m milliseconds; see sleep(...).
Raises
  • Java_exception if m is invalid
  • Java_exception if the thread is interrupted
 
val sleep_nanos : java_long -> java_int -> unit
sleep m n waits for m milliseconds plus n nanoseconds; see sleep(...).
Raises
  • Java_exception if m or n is invalid
  • Java_exception if the thread is interrupted
 
val start : t -> unit
Starts the execution of the thread; see start(...).
Raises Java_exception if the thread has already been started
 
val yield : unit -> unit
Indicates that the current thread wants to yield its use of a processor; see yield(...).
 

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.