next up previous contents
Next: MLton.Word, MLton.Word8 Up: MLton Previous: MLton.TextIO   Contents


MLton.Thread

Threads are data structures that will begin computing when switched to with a value.
signature MLTON_THREAD =
   sig
      type 'a t

      val atomicBegin: unit -> unit
      val atomicEnd: unit -> unit
      val new: ('a -> unit) -> 'a t
      val prepend: 'a t * ('b -> 'a) -> 'b t
      val switch: ('a t -> 'b t * 'b) -> 'a
      val switch': ('a t -> 'b t * (unit -> 'b)) -> 'a
   end

type 'a t

the type of threads that expect a value of type 'a.

atomicBegin ()

begin a critical section.

atomicEnd ()

end a critical section.

new f

create a new thread that, when run, applies f to the value given to the thread.

prepend (t, f)

create a new thread (destroying t in the process) that first applies f to the value given to the thread and then continues with t. This is a constant time operation.

switch f

apply f to the current thread to get (t, v), and then start running thread t on value v. It is an error for f to perform another switch. Also, f is guaranteed to run atomically.

switch' f

apply f to the current thread to get (t, g), and then starts running thread t computing the value g ().