jeudi 23 août 2018

How to convert c++ multi-thread code to javascript?

I have a multi-thread c++ code. I want to convert it to javascript file

#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);
}

I use emscripten to to convert it to html

em++ test.cpp -o test.html

then I use firefox/chrome to open it. There is an error to create the thread.

My question is does js support c++ multi-thread code?

Aucun commentaire:

Enregistrer un commentaire