emscripten-core / emscripten-core/emscripten
Call my callback function in other thread with proxying.h
- Vorherrschende Sprache
- C++
- Sterne
- 27.6k
- Forks
- 3.6k
- Ø Merge
- 1 T. 14 Std.
- Gemergte PRs (30 T.)
- 125
Beschreibung
When I call my "**cb**" pointer function in the main thread, my "**cb_js**" function on the JS side is triggered.
However, when I do this in a separate thread, it does not work.
**C++:**
```
void (*cb)(int a);
extern "C" EMSCRIPTEN_KEEPALIVE void init_cb(void(*cb_js)(int a)){
cb = cb_js;
}
void process(int a){
cb(a);
}
extern "C" EMSCRIPTEN_KEEPALIVE void Start(){
process(5);
}
```
**JS:**
```
function cb_js(a){
console.log(a);
}
let ptr_cb = Module.addFunction(cb_js, "vi");
Module.ccall("init_cb", "void", ["number"], [ptr_cb]);
Module.ccall("Start", "void", [], []);
```
The codes above are working.
However, when **I want to access my callback function in a other thread** as follows, I cannot access it.
I think this is possible with "**proxying.h**".
**C++:**
```
extern "C" EMSCRIPTEN_KEEPALIVE void Start(){
std::thread([](){
process(5);
}).join();
```
}
Beitragsleitfaden
Rechercherichtung
Beginne mit proxying.h und den gezeigten Einstiegspunkten Start, init_cb und process; vergleiche die Callback-Ausführung im Hauptthread mit dem std::thread-Pfad und prüfe die Threading-Einschränkungen. Erledigt bedeutet, festzustellen, ob dieses Callback-Muster unterstützt wird, und entweder das Verhalten zu korrigieren oder den erforderlichen proxying-Ansatz zu dokumentieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- cpp, javascript, wasm
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100