WebAssembly/wasi-libc

clock_nanosleep doesn't work as expected

daichifukui opened this issue · 9 comments

Description

clock_nanosleep with TIMER_ABSTIME does not return if it is called in a thread different from the main thread.

Conditions

  • wasi-libc HEAD: ce2f157
  • Compiler: clang version 16.0.0, Target: wasm32-unknown-wasi, Thread model: posix, InstalledDir: /home/user/wasi-sdk-20.0/bin
  • Runtime: wasmer 4.1.1

Steps to reproduce

# view source code
$ cat clock_nanosleep_abs.c
#include <time.h>
#include <stdio.h>

int main(void)
{
        int ret;
        struct timespec ts;
        clock_gettime(CLOCK_MONOTONIC,&ts);
        ts.tv_sec += 1;
        ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL);
        if (ret)
                perror("clock_nanosleep");
        return 0;
}

# compile
$  /home/user/wasi-sdk-20.0/bin/clang \
--sysroot=/home/user/wasi-libc/sysroot \
-Wall \
-Wno-nonnull \
-Wextra \
-O2 \
-Wl,--max-memory=4294967296 \
-Wl,--export-dynamic \
clock_nanosleep_abs.c \
-o cn_abs

# run
$  /home/user/.wasmer/bin/wasmer run --enable-all ./cn_abs

# the program should return in 1 second but it doesn't actually

Expected behaviour

clock_nanosleep returns when the requested time expires

Actual behaviour

clock_nanosleep does not return even after the requested time expires

abrown commented

To check whether this is a libc problem or an engine problem, could you run this in some other engines, like Wasmtime or WAMR?

Hi,

To check whether this is a libc problem or an engine problem, could you run this in some other engines, like Wasmtime or WAMR?

Thanks for the reply.

I've tried wasmtime, wasmedge, and iwasm and followed the steps to reproduce shown above.
The result shows that clock_nanosleep lets the program sleep for expected duration with all of the runtimes.
In short, clock_nanosleep works fine with the runtimes except for wasmer.
So, is this issue more related to wasmer than wasi-libc?

FYI, the version of each runtime is as follows:

  • wasmtime-cli 8.0.1
  • wasmedge version 0.13.1
  • iwasm 1.2.3
abrown commented

Yeah, it looks that way. Do you want to move this issue there?

Yeah, it looks that way. Do you want to move this issue there?

Yes, I want to, but it looks like I am not allowed to transfer this issue to another repo.
Can I ask you to move it there?

abrown commented

Ah, shoot, I can't either. I guess we would need to have maintainer privileges on both repositories. Maybe just recreate it there and then we can close this one?

sbc100 commented

I think you can only move issues with an single org/user.

I'd love to transfer this issue to the wasmer repo. Is that something we can do here?

We'll just have to create a new issue on github.com/wasmerio/wasmer and close this one, transferring requires privileges on both repos.

I've opened a new issue on wasmerio/wasmer - wasmerio/wasmer#4249.
Let's close this one.
I appreciate your comments.