Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/core/pthread/emscripten_futexes.c
4154 views
1
#include <assert.h>
2
#include <emscripten/threading.h>
3
#include <errno.h>
4
#include <limits.h>
5
#include <stdio.h>
6
7
int main() {
8
// This should return -EWOULDBLOCK.
9
int futex_value = 42;
10
int rc = emscripten_futex_wait(&futex_value, futex_value + 1, 0);
11
assert(rc == -EWOULDBLOCK);
12
13
// This should return -ETIMEDOUT.
14
rc = emscripten_futex_wait(&futex_value, futex_value, 1);
15
assert(rc == -ETIMEDOUT);
16
17
// Check that this thread has removed itself from the wait queue.
18
rc = emscripten_futex_wake(&futex_value, INT_MAX);
19
assert(rc == 0);
20
21
// Check that the wait address is checked for validity.
22
void *bad_address = (void *) ~(uintptr_t) 0;
23
rc = emscripten_futex_wake(bad_address, futex_value);
24
// TODO: Should these return EFAULT instead?
25
assert(rc == -EINVAL/*-EFAULT*/);
26
rc = emscripten_futex_wake(NULL, 1);
27
assert(rc == -EINVAL/*-EFAULT*/);
28
29
printf("OK\n");
30
}
31
32