emscripten-core / emscripten-core/emscripten
std::condition_variable_any::notify_one() stucks.
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
```
➜ src emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.34 (57b21b8fdcbe3ebb523178b79465254668eab408)
clang version 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1e901a3872f4b)
```
In my app I use a main thread:
```
std::thread main_loop = std::thread(&Document::MainLoop, this);
```
In this thread I wait for a conditional variable:
```
std::unique_lock lock(tasks_mutex);
if (tasks.empty() && undos.empty() && redos.empty())
{
printf("Wait on conditional\n");
if (next_circle.wait_for(lock, caret_settings.blink_delay * 1ms) == std::cv_status::timeout) //wait for tasks
{
caret->Blink();
continue;
}
}
```
Somewhere in the code I notify it:
```
next_circle.notify_one();
```
So, in the Linux app it works fine. In the webasm app it works so:
1. Waiting on "next_circle.wait_for()" is infinite every time.
2. Code "next_circle.notify_one()" passes about 4 times, after it hangs forever. I tried to debug it, the debugger shows waiting in the conditional variable's mutex... But who is the second thread who locks it I can't find.
My question is: how should I work with conditional variables? What's wrong with this code? Are C++ conditional variables supported in emscripten?
Contributor guide
Assessment
This issue has not been assessed yet.