emscripten-core / emscripten-core/emscripten
Writing to `std::cout` disables wasm workers stdout
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.24 (68a9f990429e0bcfb63b1cde68bad792554350a5)
clang version 16.0.0 (https://github.com/llvm/llvm-project 277c382760bf9575cfa2eac73d5ad1db91466d3f)
Target: wasm32-unknown-emscripten
Thread model: posix
```
I have the following test program:
```c++
#include
#include
#include
#include
std::atomic_uint32_t counter = 0;
void printCounter(const std::string& prefix) {
std::string s = prefix + " counter " + to_string(counter) + "\n";
printf("%s", s.c_str());
}
void workerLoop() {
while(true) {
printCounter("W");
counter++;
emscripten_wasm_worker_sleep(1 * 1000000000);
}
}
void mainLoop() {
//std::cout << "Main loop" << std::endl;
printCounter("M");
}
int main() {
//std::cout << "Main: before creation" << std::endl;
printf("Main: before creation printf\n");
auto worker = emscripten_malloc_wasm_worker(4096);
emscripten_wasm_worker_post_function_v(worker, &workerLoop);
//std::cout << "Main: after creation" << std::endl;
printf("Main: after creation printf\n");
emscripten_set_main_loop(mainLoop, 1, 1);
return 0;
}
```
Built with:
```
emcc -sWASM_WORKERS test.cpp -o test.html
```
That produces the following (expected) output in the browser JS console:
```
emrun test.html
Main: before creation printf
Main: after creation printf
M counter 0
W counter 0
M counter 1
W counter 1
M counter 2
W counter 2
M counter 3
W counter 3
...
```
but, as soon as I decomment any one of the 3 writes to `std::cout`, I don't see the prints coming from the worker anymore. This happens only with `std::cout`, as you can see `printf()` does not alter the output of the program.
Is this behavior normal? Am i missing some compiler flag?
Contributor guide
Assessment
This issue has not been assessed yet.