最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - HTTP request on thread - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论