emscripten-core / emscripten-core/emscripten

std::condition_variable_any::notify_one() stucks.

Aperta
#18,992 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
multithreading
Lingua principale
C++
Stelle
27.6k
Fork
3.6k
Merge medio
1g 14h
PR unite (30g)
125

Descrizione

```
➜ 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?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Il report cita emcc 3.1.34 e i punti di chiamata di std::condition_variable_any wait_for() e notify_one(), ma non contiene file sorgente né test. Inizia riducendo l’uso mostrato di thread e variabili di condizione a una riproduzione minima con Emscripten/WebAssembly, quindi confrontane il comportamento con Linux. Il lavoro è completato quando la riproduzione stabilisce se wait_for() va in timeout e se notify_one() continua a risvegliare il thread in attesa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, wasm
Ambito
compilers, operating-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.