1;;! threads = true
2
3;; test that looping notify eventually unblocks a parallel waiting thread
4(module $Mem
5  (memory (export "shared") 1 1 shared)
6)
7
8(thread $T1 (shared (module $Mem))
9  (register "mem" $Mem)
10  (module
11    (memory (import "mem" "shared") 1 10 shared)
12    (func (export "run") (result i32)
13      (memory.atomic.wait32 (i32.const 0) (i32.const 0) (i64.const -1))
14    )
15  )
16  ;; test that this thread eventually gets unblocked
17  (assert_return (invoke "run") (i32.const 0))
18)
19
20(thread $T2 (shared (module $Mem))
21  (register "mem" $Mem)
22  (module
23    (memory (import "mem" "shared") 1 1 shared)
24    (func (export "notify-0") (result i32)
25      (memory.atomic.notify (i32.const 0) (i32.const 0))
26    )
27    (func (export "notify-1-while")
28      (loop
29        (i32.const 1)
30        (memory.atomic.notify (i32.const 0) (i32.const 1))
31        (i32.ne)
32        (br_if 0)
33      )
34    )
35  )
36  ;; notifying with a count of 0 will not unblock
37  (assert_return (invoke "notify-0") (i32.const 0))
38  ;; loop until something is notified
39  (assert_return (invoke "notify-1-while"))
40)
41
42(wait $T1)
43(wait $T2)
44