1 (* Copyright (C) 2009 Matthew Fluet.
2 * Copyright (C) 2004-2006 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
9 signature MLTON_THREAD =
11 structure AtomicState :
13 datatype t = NonAtomic | Atomic of int
15 val atomically: (unit -> 'a) -> 'a
16 val atomicBegin: unit -> unit
17 val atomicEnd: unit -> unit
18 val atomicState: unit -> AtomicState.t
28 * as switch, but assumes an atomic calling context. Upon
29 * switch-ing back to the current thread, an implicit atomicEnd is
32 val atomicSwitch: ('a t -> Runnable.t) -> 'a
34 * create a new thread that, when run, applies f to
35 * the value given to the thread. f must terminate by
36 * switch-ing to another thread or exiting the process.
38 val new: ('a -> unit) -> 'a t
40 * create a new thread (destroying t in the process) that first
41 * applies f to the value given to the thread and then continues
42 * with t. This is a constant time operation.
44 val prepend: 'a t * ('b -> 'a) -> 'b t
46 * create a new runnable thread (destroying t in the process)
47 * that will evaluate t on v.
49 val prepare: 'a t * 'a -> Runnable.t
51 * apply f to the current thread to get rt, and then start
52 * running thread rt. It is an error for f to
53 * perform another switch. f is guaranteed to run
56 val switch: ('a t -> Runnable.t) -> 'a