Path: blob/main/test/core/pthread/emscripten_futexes.c
4154 views
#include <assert.h>1#include <emscripten/threading.h>2#include <errno.h>3#include <limits.h>4#include <stdio.h>56int main() {7// This should return -EWOULDBLOCK.8int futex_value = 42;9int rc = emscripten_futex_wait(&futex_value, futex_value + 1, 0);10assert(rc == -EWOULDBLOCK);1112// This should return -ETIMEDOUT.13rc = emscripten_futex_wait(&futex_value, futex_value, 1);14assert(rc == -ETIMEDOUT);1516// Check that this thread has removed itself from the wait queue.17rc = emscripten_futex_wake(&futex_value, INT_MAX);18assert(rc == 0);1920// Check that the wait address is checked for validity.21void *bad_address = (void *) ~(uintptr_t) 0;22rc = emscripten_futex_wake(bad_address, futex_value);23// TODO: Should these return EFAULT instead?24assert(rc == -EINVAL/*-EFAULT*/);25rc = emscripten_futex_wake(NULL, 1);26assert(rc == -EINVAL/*-EFAULT*/);2728printf("OK\n");29}303132