I've spent some days trying to run a HTTP request on a background thread (with -pthread / USE_PTHREADS), and im completely stuck
I have tried using Xhr, JS fetch, and finally emscripten_fetch, and none work (all lead to hang)
I will focus on emscripten_fetch here as this should theoretically be the simplest
compile flags:
-std=c++20
-pthread
-s USE_PTHREADS=1
-s PTHREAD_POOL_SIZE=8
-s ALLOW_BLOCKING_ON_MAIN_THREAD=1
-s FETCH=1
code snippet (edited by hand/reduced, but to illustrate even this hangs the browser at emscripten_fetch line):
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcopy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_SYNCHRONOUS;
emscripten_fetch_t * fetch = emscripten_fetch(&attr, "testfile.json");
UInt32 response_code = fetch->status;
emscripten_fetch_close(fetch);
return Response(response_code);
Before you ask..
- this IS NOT ON MAIN THREAD
- and otherwise, threads are working ok (as tested by emulating a workload with a loop with sleep)
It also doesn't work if async/with the callbacks.
I have tested with a full "http://localhost:8000/testfile.json" url also, same problem.
Any help would be appreciated, completely stuck here.