-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy paththreads.h
69 lines (52 loc) · 1.27 KB
/
threads.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//==================================================================
// File : threads.h
// Author : rsagalyn
// Date : Aug 25, 2013
// Description : Abstract thread encapsulation class
//==================================================================
#ifndef THREADS_H
#define THREADS_H
#include <cstring>
#include <iostream>
#include <pthread.h>
#include "tsp.h"
using namespace std;
// Abstract Thread class
class Thread
{
private:
// Internally track thread ids
pthread_t _id;
// Serves as global function for pthraed_create
// Internally calls member function run
static void *exec(void *thr);
// Prevent copying
Thread(const Thread& arg);
// Prevent assignment
Thread& operator=(const Thread& rhs);
protected:
// Pure virtual function, to implement with code thread should run
virtual void run() = 0;
public:
// Constructor
Thread() {
mytsp = NULL;
_id = 0;
my_id = start_node = -1;
};
// Destructor
virtual ~Thread() {};
// Starts the internal thread
void start();
// Wait for internal thread to exit
void join();
// Get thread id of internal thread
long get_tid() {return (long)_id;}
// Index of node to start touring at
int start_node;
// Pointer to TSP object
TSP *mytsp;
// Assigned ID (for tracking purposes)
int my_id;
};
#endif