Download upstream/emscripten/test/wasm_worker/cpp11_thread_local.cpp from arudradey/flst: direct link, hf CLI and curl.
- Browser
- Download file 834 Bytes
-
https://huggingface.co/arudradey/flst/resolve/main/upstream/emscripten/test/wasm_worker/cpp11_thread_local.cpp
- Command line
-
hf download hf://arudradey/flst/upstream/emscripten/test/wasm_worker/cpp11_thread_local.cpp
-
curl -L -o cpp11_thread_local.cpp https://huggingface.co/arudradey/flst/resolve/main/upstream/emscripten/test/wasm_worker/cpp11_thread_local.cpp
834 Bytes
| thread_local int tls = 1; | |
| void main_thread_func() { | |
| assert(!emscripten_current_thread_is_wasm_worker()); | |
| emscripten_outf("%d", tls); | |
| REPORT_RESULT(tls); | |
| } | |
| void worker_main() { | |
| assert(emscripten_current_thread_is_wasm_worker()); | |
| assert(tls != 42); | |
| assert(tls != 0); | |
| assert(tls == 1); | |
| tls = 123456; // Try to write garbage data to the memory location. | |
| emscripten_wasm_worker_post_function_v(0, main_thread_func); | |
| } | |
| char stack[1024]; | |
| int main() { | |
| emscripten_outf("%d", tls); | |
| assert(!emscripten_current_thread_is_wasm_worker()); | |
| tls = 42; | |
| emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); | |
| emscripten_wasm_worker_post_function_v(worker, worker_main); | |
| } | |