Skip to content

Commit f6b16a7

Browse files
authored
wasi-threads: fix use of wait in test (#5858)
As @yamt points out [here], the `wait`/`notify` pairing used in this manual WAT test was not effective. The `wait` always immediately returned, meaning that the main thread essentially spins until a counter is atomically incremented. This is fine for test correctness, but was not the original intent, which was lost in a refactoring. This change uses the `$i` local to keep track of the counter value we expect to see for the `wait`, so that the `wait`/`notify` pair actually waits as expected. [here]: #5484 (comment)
1 parent 0521155 commit f6b16a7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tests/all/cli_tests/threads.wat

+8-5
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
(drop (call $__wasi_thread_spawn (i32.const 0)))
2222

2323
;; Wait for all the threads to notify us that they are done.
24+
(local.set $i (i32.const 0))
2425
(loop $again
25-
;; Retrieve the i32 at address 128, compare it to -1 (it should always
26-
;; fail) and load it atomically to check if all three threads are
27-
;; complete. This wait is for 1ms or until notified, whichever is first.
28-
(drop (memory.atomic.wait32 (i32.const 128) (i32.const -1) (i64.const 1000000)))
29-
(br_if $again (i32.lt_s (i32.atomic.load (i32.const 128)) (i32.const 3)))
26+
;; Wait for the i32 at address 128 to be incremented by each thread. We
27+
;; maintain a local $i with the atomically loaded value as the expected
28+
;; wait value and to check if all three threads are complete. This wait is
29+
;; for 1ms or until notified, whichever is first.
30+
(drop (memory.atomic.wait32 (i32.const 128) (local.get $i) (i64.const 1000000)))
31+
(local.set $i (i32.atomic.load (i32.const 128)))
32+
(br_if $again (i32.lt_s (local.get $i) (i32.const 3)))
3033
)
3134

3235
;; Print "Done".

0 commit comments

Comments
 (0)