将C++代码使用wasm编译成js代码,在调用到C++内部的std::thread时报错。
C++代码片段如下:
#include <thread>
#include <iostream>
EM_PORT_API(int) testThread(int a){
std::thread t1;
auto lambda = [](int a) {
std::cout << a << '\n';
};
std::thread thread(lambda, 10);
return 1;
}
编译代码:emcc -std=c++11 api.cpp -o api.js
报错堆栈:
Uncaught (in promise) RuntimeError: Aborted(native code called abort())
at abort (api.js:919:11)
at _abort (api.js:1285:7)
at api.wasm:0x22eff
at api.wasm:0x1142
at api.wasm:0xfca
at Object._testThread (api.js:963:22)
at Module.onRuntimeInitialized (api.html:11:26)
at doRun (api.js:5243:71)
at run (api.js:5260:5)
at runCaller (api.js:5165:19)
请问有遇到相同的问题吗?应该怎么解决,谢谢