我有一个多线程c ++代码。我想将其转换为javascript文件
#include <iostream>
#include <cstdlib>
#include <pthread.h>
using namespace std;
#define NUM_THREADS 5
void *PrintHello(void *threadid) {
long tid;
tid = (long)threadid;
cout << "Hello World! Thread ID, " << tid << endl;
pthread_exit(NULL);
}
int main () {
pthread_t threads[NUM_THREADS];
int rc;
int i;
for( i = 0; i < NUM_THREADS; i++ ) {
cout << "main() : creating thread, " << i << endl;
rc = pthread_create(&threads[i], NULL, PrintHello, (void *)i);
if (rc) {
cout << "Error:unable to create thread!!!" << rc << endl;
exit(-1);
}
}
pthread_exit(NULL);
}
我使用emscripten将其转换为html
em++ test.cpp -o test.html
然后我使用Firefox / chrome打开它。创建线程出错。
我的问题是js是否支持c ++多线程代码?