Lines Matching defs:lock
48 N.B. Mutex.lock is not an interruption point even though it can result
117 (* Mutexes. A mutex provides simple mutual exclusion. A thread can lock
118 a mutex and until it unlocks it no other thread will be able to lock it.
120 there is no other process attempting to lock the mutex. *)
124 (* lock: Lock a mutex. If the mutex is currently locked the thread is
125 blocked until it is unlocked. If a thread tries to lock a mutex that
127 N.B. "lock" is not an interruption point (a point where synchronous
129 val lock: mutex -> unit
133 (* trylock: Attempt to lock the mutex. Returns true if the mutex was not
148 use is for one thread to lock a mutex, test the reference and then wait on
149 the condition variable, releasing the lock on the mutex while it does so.
150 Another thread may then lock the mutex, update the reference, unlock the
152 and reacquires the lock allowing the thread to test the updated reference
153 with the lock held.
445 will again be 1 but if some other thread tried to lock it the result will be
449 The cost of contention on the lock is very high. To try to avoid this we
450 first loop (spin) to see if we can get the lock without contention. *)
458 fun lock (m: mutex): unit =
464 then () (* We've acquired the lock. *)
465 else (* It's locked. We return when we have the lock. *)
468 lock m (* Try again. *)
480 set the value to 1 here to release the lock. If another thread
483 still locked it will enter the RTS and try to acquire the lock
486 since it allows another thread to acquire the lock immediately
491 acquire a lock. *)
498 (* Try to lock the mutex. If it was previously unlocked then lock it and
500 the possibility that the thread that has locked it could release the lock
503 There is a small chance that another thread could lock the mutex between the
509 then true (* We've acquired the lock. *)
510 else false (* The lock was taken. *)
517 (* A condition variable contains a lock and a list of suspended threads. *)
518 type conditionVar = { lock: Mutex.mutex, threads: thread list ref }
520 { lock = Mutex.mutex(), threads = nvref nil }
526 fun innerWait({lock, threads}: conditionVar, m: Mutex.mutex, t: Time.time option) : bool =
539 SOME time => threadCondVarWaitUntil(lock, time)
540 | NONE => threadCondVarWait lock
542 val () = Mutex.lock lock (* Get the lock again. *)
553 Mutex.unlock lock;
560 Mutex.unlock lock;
568 handle exn => (threads := removeThis(! threads); Mutex.unlock lock; raise exn);
574 Mutex.lock lock; (* Lock the internal mutex. *)
591 need to reacquire the lock unless we were handling interrupts
597 we reacquire the lock. If it was set to InterruptAsynchOnce this
601 InterruptDefer => (* Shouldn't happen? *) Mutex.lock m
602 | InterruptSynch => Mutex.lock m
611 (* Normal return. Reacquire the lock before returning. *)
612 Mutex.lock m;
640 fun signalOrBroadcast({lock, threads}: conditionVar, wakeThreads) : unit =
646 interrupt which could leave the internal lock in an inconsistent state. *)
650 (* Get the condition var lock. *)
651 Mutex.lock lock;
653 Mutex.unlock lock;
698 val () = lock m