emscripten-core / emscripten-core/emscripten
Call my callback function in other thread with proxying.h
- Lingua principale
- C++
- Stelle
- 27.6k
- Fork
- 3.6k
- Merge medio
- 1g 14h
- PR unite (30g)
- 125
Descrizione
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();
```
}
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia da proxying.h e dagli entry point mostrati Start, init_cb e process; confronta l’esecuzione della callback sul thread principale con il percorso std::thread e verifica i vincoli di threading. Il lavoro è completo quando si determina se questo pattern di callback è supportato e si corregge il comportamento oppure si documenta l’approccio di proxying richiesto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp, javascript, wasm
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100