-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocgen.cc
45 lines (39 loc) · 1.04 KB
/
procgen.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "procgen.h"
#include "instance.h"
#include <pthread.h>
#include <thread>
namespace ProcGen
{
TaskQueue taskQueue;
ResultQueue resultQueue;
pthread_t parentThreadId;
void start() {
// threads.reserve(numThreads);
/* EM_ASM({
console.log('main thread', $0, $1);
}, pthread_self(), numThreads); */
for (int i = 0; i < numThreads; i++) {
// std::cout << "create thread" << std::endl;
std::thread([]() -> void {
/* EM_ASM({
console.log('worker thread', $0);
}, pthread_self()); */
runLoop();
}).detach();
}
}
void runLoop() {
taskQueue.runLoop();
}
void initialize()
{
parentThreadId = pthread_self();
}
PGInstance *createInstance(int seed, int chunkSize) {
PGInstance *instance = new PGInstance(seed, chunkSize);
return instance;
}
void destroyInstance(PGInstance *instance) {
delete instance;
}
}