1 package frost.threads
2
3 ====================================================================================================
4 A condition variable which helps multiple [Thread]s coordinate their scheduling. `Notifier` is not
5 necessary from within safe Frost code; normally you would use [MessageQueue] to coordinate between
6 threads. `Notifier` generally only comes into play when [Lock]s are necessary due to unsafe
7 threading.
8 ====================================================================================================
9 class Notifier : Immutable {
10 @private
11 def nativeNotifier:Int64
12
13 @private
14 def lock:Lock
15
16 init(lock:Lock) {
17 self.lock := lock
18 create()
19 }
20
21 ================================================================================================
22 Blocks the current thread until another thread calls the [notify()] or [notifyAll()] method on
23 this notifier.
24 ================================================================================================
25 @external(frostNotifierWait)
26 method wait()
27
28 ================================================================================================
29 If any other threads are waiting on this `Notifier`, chooses one of them (in a system-dependent
30 fashion) and wakes it up.
31 ================================================================================================
32 @external(frostNotifierNotify)
33 method notify()
34
35 ================================================================================================
36 If any other threads are waiting on this `Notifier`, wakes up all of them.
37 ================================================================================================
38 @external(frostNotifierNotifyAll)
39 method notifyAll()
40
41 @override
42 method cleanup() {
43 destroy()
44 }
45
46 @private
47 @external(frostNotifierCreate)
48 method create()
49
50 @private
51 @external(frostNotifierDestroy)
52 method destroy()
53 }