Skip to content

clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME) sleeps forever #16453

Closed
@tiran

Description

@tiran

clock_nanosleep() with monotonic clock and absolute time sleeps forever. strace shows that node is spinning fast in a FUTEX lock.

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.2 (a77b559a8b40b7e89fc8c17e41034128df9543e4)
clang version 14.0.0 (https://github.com/llvm/llvm-project 782c0dd1a1c235afb09a34e7da4a1267ead14765)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin

Reproducer:

#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <time.h>

int main(void) {
    struct timespec deadline;
    clock_gettime(CLOCK_MONOTONIC, &deadline);
    deadline.tv_sec += 1;
    fprintf(stdout, "%li\n", time(NULL));
    clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &deadline, NULL);
    fprintf(stdout, "%li\n", time(NULL));
}
$ gcc -o nanosleep nanosleep.c
$ ./nanosleep
1646748808
1646748809
$ emcc -o nanosleep.js nanosleep.c
$ time node nanosleep.js
1646748866
^C

real    0m9.480s
user    0m9.483s
sys     0m0.033s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions