-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstractthread.cpp
More file actions
33 lines (28 loc) · 857 Bytes
/
Copy pathabstractthread.cpp
File metadata and controls
33 lines (28 loc) · 857 Bytes
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
#include <pthread.h>
#include <iostream>
using namespace std;
#include "pieces.h"
#include "abstractthread.h"
void * AbstractThread::Callback ( void * arg ) {
AbstractThread * copy = (AbstractThread *)arg;
void * status = copy->ThreadWorker((void *)"");
delete copy;
pthread_exit ( status );
}
void AbstractThread::Start ( int n ) {
int limit = (n + threadCounter);
for(int i = threadCounter; i < limit; i++) {
if(i == MAX) { break; }
pthread_create ( &threads[i], NULL, Callback, (void*)this->Copy() );
threadCounter++;
}
}
void ** AbstractThread::Wait ( ) {
void * status = NULL;
void ** threadResults = new void*[threadCounter];
for(int i = 0; i < threadCounter; i++) {
pthread_join ( threads[i], &status );
threadResults[i] = status;
}
return threadResults;
}