Skip to content

Commit ed9f2a3

Browse files
stephenduong1004sbc100
authored andcommitted
Fix infinite hang in emscripten_futex_wait
This bug was introduced in #26471. This PR is based on #26586. Thanks @stephenduong1004!
1 parent 46543e7 commit ed9f2a3

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

system/lib/pthread/emscripten_futex_wait.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ int emscripten_futex_wait(volatile void *addr, uint32_t val, double max_wait_ms)
224224
}
225225
// If remainder_ns is negative it means we want wait forever, and we don't
226226
// need to decrement remainder_ns in that case.
227-
if (wakeup_interval && remainder_ns > 0) {
227+
if (wakeup_interval && remainder_ns >= 0) {
228228
remainder_ns -= wakeup_interval;
229229
if (remainder_ns <= 0) {
230230
break;

test/core/pthread/emscripten_futexes.c renamed to test/core/pthread/emscripten_futex_api_basics.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ int main() {
1414
rc = emscripten_futex_wait(&futex_value, futex_value, 1);
1515
assert(rc == -ETIMEDOUT);
1616

17+
// As should this.
18+
rc = emscripten_futex_wait(&futex_value, futex_value, 0);
19+
assert(rc == -ETIMEDOUT);
20+
1721
// Check that this thread has removed itself from the wait queue.
1822
rc = emscripten_futex_wake(&futex_value, INT_MAX);
1923
assert(rc == 0);
File renamed without changes.

test/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9251,10 +9251,10 @@ def test_emscripten_atomics(self):
92519251
self.do_core_test('pthread/emscripten_atomics.c', cflags=['-pthread'])
92529252

92539253
@requires_pthreads
9254-
def test_emscripten_futexes(self):
9254+
def test_emscripten_futex_api_basics(self):
92559255
# This test explicitly checks behavior of passing NULL to emscripten_futex_wake() so
92569256
# need to disable the `-Wno-nonnull` to disabled these warnings.
9257-
self.do_core_test('pthread/emscripten_futexes.c', cflags=['-pthread', '-Wno-nonnull'])
9257+
self.do_core_test('pthread/emscripten_futex_api_basics.c', cflags=['-pthread', '-Wno-nonnull'])
92589258

92599259
@requires_pthreads
92609260
def test_stdio_locking(self):

0 commit comments

Comments
 (0)