Lines Matching refs:thread

26   new thread primitives in the Thread structure. This structure is modelled on 
27 the Posix thread (pthread) package but simplified and modified for ML. The aim
34 The thread package differs from pthreads in a number of ways.
35 There is no join function to wait for the completion of a thread.
41 generated in a specific thread. Alternatively an interrupt can be
46 these interrupts. A thread that is doing processor-intensive work
60 (*!The type of a thread identifier.*)
61 eqtype thread
64 (*!The type of a thread attribute. Thread attributes are
65 properties of the thread that are set initially when the thread is
66 created but can subsequently be modified by the thread itself. The
67 thread attribute type may be extended in the future to include things
68 like scheduling priority. The current thread attributes control the
69 way interrupt exceptions are delivered to the thread.
71 `EnableBroadcastInterrupt` controls whether the thread will receive an interrupt sent using
73 key. If this is false the thread will not receive them. The default
74 for a new thread if this is not specified is false.
77 thread. This includes broadcast interrupts and also interrupts directed at
78 a specific thread with the interrupt call.
79 `InterruptDefer` means the thread
80 will not receive any interrupts. However, if the thread has previously been
81 interrupted the interrupt may be delivered when the thread calls setAttributes
88 `Mutex.lock` is not an interruption point even though it can result in a thread
93 the interrupt state is changed to `InterruptSynch`. It allows a thread to tidy
96 interrupt. If this attribute is not specified when a thread is created the
103 the limit is reached the thread is sent an Interrupt exception.*)
105 (* Does this thread accept a broadcast interrupt? The default is not to
120 in a thread blocking for an indefinite period. *)
125 InterruptSynch. It allows a thread to tidy up and if necessary indicate
129 (*!Fork a thread. Starts a new thread running
130 the function argument. The attribute list gives initial values for thread attributes
131 which can be modified by the thread itself. Any unspecified attributes take
132 default values. The thread is terminated when the thread function returns, if
134 val fork: (unit->unit) * threadAttribute list -> thread
136 (*!Terminate this thread. *)
138 (*!Test if a thread is still running or has terminated. This function should be
139 used with care. The thread may be on the point of terminating and still appear
141 val isActive: thread -> bool
143 (*!Test whether thread ids are the same. This is provided for backwards compatibility
144 since `thread` is an eqtype. *)
145 val equal: thread * thread -> bool
146 (*!Return the thread identifier for the current thread. *)
147 val self: unit -> thread
150 (*!Send an Interrupt exception to a specific thread. When and indeed whether
152 of the target thread. Raises Thread if the thread is no longer running,
153 so an exception handler should be used unless the thread is known to
155 val interrupt: thread -> unit
156 (*!Send an interrupt exception to every thread which is set to accept it. *)
158 (*!If this thread is handling interrupts synchronously, test to see
162 (*!Terminate a thread. This should be used as a last resort. Normally
163 a thread should be allowed to clean up and terminate by using the
164 interrupt call. Raises Thread if the thread is no longer running,
165 so an exception handler should be used unless the thread is known to
167 val kill: thread -> unit
169 (*!Get and set thread-local store for the calling thread. The store is a
170 tagged associative memory which is initially empty for a new thread.
171 A thread can call setLocal to add or replace items in its store and
178 (*!Change the specified attribute(s) for the calling thread. Unspecified
192 (*!A mutex provides simple mutual exclusion. A thread can lock
193 a mutex and until it unlocks it no other thread will be able to lock it.
197 is delivered during the calls. A thread should use synchronous interrupt
202 (*!Lock a mutex. If the mutex is currently locked the thread is
203 blocked until it is unlocked. If a thread tries to lock a mutex that
204 it has previously locked the thread will deadlock.
205 N.B. `thread` is not an interruption point
207 interrupts are delivered) even though a thread can be blocked indefinitely. *)
210 if the mutex was not previously locked by the calling thread is undefined. *)
213 previously locked and has now been locked by the calling thread. Returns
214 false if the mutex was previously locked, including by the calling thread. *)
224 use is for one thread to lock a mutex, test the reference and then wait on
226 Another thread may then lock the mutex, update the reference, unlock the
227 mutex, and signal the condition variable. This wakes up the first thread
228 and reacquires the lock allowing the thread to test the updated reference
238 If the thread is handling interrupts synchronously this function can be interrupted
239 using the `Thread.interrupt` function or, if the thread is set to
240 accept broadcast interrupts, `Thread.broadcastInterrupt`. The thread
248 A thread should never call this function if it may receive an asynchronous
262 by another thread. *)
264 (*!Wake up one thread if any are waiting on the condition variable.
280 open Thread (* Created in INITIALISE with thread type and self function. *)
283 val equal : thread*thread->bool = op =
349 (* The thread id is opaque outside this structure but is actually a six
351 Word 0: Index into thread table (used inside the RTS only)
401 (* If there is a pending request the word in the thread object
409 and isActive: thread -> bool = RunCall.rtsCallFast1 "PolyThreadIsActive"
413 fun getAttrWord (me: thread) : Word.word =
416 fun getStackSizeAsInt (me: thread) : int =
469 (* The default for a new thread is to ignore broadcasts and handle explicit
474 (unit->unit) * word * int -> thread = RunCall.rtsCallFull3 "PolyThreadForkThread"
476 fun fork(f:unit->unit, attrs: threadAttribute list): thread =
491 (* Send an interrupt to a thread. If it returns false
492 the thread did not exist and this should raise an exception. *)
493 val threadSendInterrupt: thread -> bool = RunCall.rtsCallFast1 "PolyThreadInterruptThread"
495 fun interrupt(t: thread) =
502 val threadKillThread: thread -> bool = RunCall.rtsCallFast1 "PolyThreadKillThread"
504 fun kill(t: thread) =
535 will again be 0 but if some other thread tried to lock it the result will be
536 one or positive. In that case the unlocking thread needs to call in to the
537 RTS to wake up the blocked thread.
569 (* Another thread has blocked and we have to release it. We can safely
570 set the value to 0 here to release the lock. If another thread
572 Equally, if another thread incremented the count and saw it was
576 since it allows another thread to acquire the lock immediately
590 the possibility that the thread that has locked it could release the lock
593 There is a small chance that another thread could lock the mutex between the
608 type conditionVar = { lock: Mutex.mutex, threads: thread list ref }
618 val me = self() (* My thread id. *)
713 (* This call wakes up the specified thread. If the thread has already been
715 it wakes up the thread and returns true. We have to use this because
716 we define that if a thread is interrupted before it is signalled then
718 val threadCondVarWake: thread -> bool = RunCall.rtsCallFast1 "PolyThreadCondVarWake"
720 (* Wake a single thread if we can (signal). *)
722 | wakeOne (thread::rest) =
723 if threadCondVarWake thread
725 else thread :: wakeOne rest
728 | wakeAll (thread::rest) = (threadCondVarWake thread; wakeAll rest)
760 and prettyThread _ _ (_: Thread.Thread.thread) = PolyML.PrettyString "?"