emscripten-core / emscripten-core/emscripten
select will timeout even if timeout is set to NULL
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Please include the following in your bug report:
**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.8 (3ff7eff373d31d8c0179895165462019221f192e)
clang version 15.0.0 (https://github.com/llvm/llvm-project 80ec0ebfdc5692a58e0832125f2c6a991df9d63f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\Users\simon\Desktop\software\emsdk\upstream\bin
**Failing command line in full:**
compiling and linking are good.
emcc -pthread -sPTHREAD_POOL_SIZE=2 test.c
node --experimental-wasm-threads --experimental-wasm-bulk-memory .\a.out.js
**Source code**
```c
#include
#include
#include
#include
int pipefd[2];
static void * __select_thread(void *arg)
{
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(pipefd[0], &rfds);
int ret;
char ch;
while (1) {
ret = select(pipefd[0] + 1, &rfds, NULL, NULL, NULL);
printf("select returned %d\n", ret);
if (0 == ret) {
FD_SET(pipefd[0], &rfds);
} else {
read(pipefd[0], &ch, 1);
}
}
return NULL;
}
int main(void)
{
pipe(pipefd);
char ch = 0;
write(pipefd[1], &ch, 1);
pthread_t thread;
pthread_create(&thread, NULL, __select_thread, NULL);
pthread_join(thread, NULL);
printf("exit\n");
return 0;
}
```
**Desired output**
On Ubuntu, the output is:
simonqian@simonqian-VirtualBox:~$ gcc test.c -lpthread
simonqian@simonqian-VirtualBox:~$ ./a.out
select returned 1
On nodejs, the output is:
PS Z:\> emcc -pthread -sPTHREAD_POOL_SIZE=2 test.c
PS Z:\> node --experimental-wasm-threads --experimental-wasm-bulk-memory .\a.out.js
select returned 1
select returned 0
select returned 0
select returned 0
select returned 0
select returned 0
......
Contributor guide
Assessment
This issue has not been assessed yet.