SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
thread_management.h
Go to the documentation of this file.
1 
5 #ifndef THREAD_MANAGEMENT_H
6 #define THREAD_MANAGEMENT_H
7 
8 //Currently only works with pthreads in UNIX
9 
10 #ifdef _WIN32
11 //Make win threads thing
12 #else
13 #include <pthread.h>
14 #endif
15 
16 namespace skepu
17 {
18 
19 #ifdef _WIN32
20 //Make win threads thing
21 #else
22 
23 #define THREAD_FINISH pthread_exit(NULL);
24 
35 class Threads
36 {
37 
38 public:
39  typedef pthread_t ThreadID;
40  typedef void ThreadFuncArg;
41  typedef void *(*ThreadFunc)(void*);
42 
50  void fork(ThreadFunc func, ThreadFuncArg* arg, ThreadID* thread)
51  {
52  int err;
53  err = pthread_create(thread, NULL, func, arg);
54  if(err) {std::cerr<<"ERROR creating threads\n";}
55  }
56 
62  void join(ThreadID thread)
63  {
64  pthread_join(thread, NULL);
65  }
66 
72  void cancel(ThreadID thread)
73  {
74  pthread_cancel(thread);
75  }
76 
77 };
78 
79 // class Mutex
80 // {
81 // public:
82 // Mutex()
83 // {
84 // pthread_mutex_init(&m_mutex, NULL);
85 // }
86 // ~Mutex()
87 // {
88 // pthread_mutex_destroy(&m_mutex);
89 // }
90 //
91 // void lock()
92 // {
93 // pthread_mutex_lock(&m_mutex);
94 // }
95 //
96 // void tryLock()
97 // {
98 // pthread_mutex_trylock(&m_mutex);
99 // }
100 //
101 // void unlock()
102 // {
103 // pthread_mutex_unlock(&m_mutex);
104 // }
105 //
106 // private:
107 // pthread_mutex_t m_mutex;
108 // };
109 //
110 // class Condition
111 // {
112 // public:
113 // Condition()
114 // {
115 // pthread_cond_init(&m_condition, NULL);
116 // pthread_mutex_init(&m_mutex, NULL);
117 // }
118 // ~Condition()
119 // {
120 // pthread_cond_destroy(&m_condition);
121 // pthread_mutex_destroy(&m_mutex);
122 // }
123 //
124 // void signal()
125 // {
126 // pthread_cond_signal(&m_condition);
127 // }
128 //
129 // void wait()
130 // {
131 // pthread_cond_wait(&m_condition, &m_mutex);
132 // }
133 //
134 // void lock()
135 // {
136 // pthread_mutex_lock(&m_mutex);
137 // }
138 //
139 // void tryLock()
140 // {
141 // pthread_mutex_trylock(&m_mutex);
142 // }
143 //
144 // void unlock()
145 // {
146 // pthread_mutex_unlock(&m_mutex);
147 // }
148 //
149 //
150 // private:
151 // pthread_cond_t m_condition;
152 // pthread_mutex_t m_mutex;
153 // };
154 
155 #endif
156 
157 
158 }
159 
160 #endif
161 
void cancel(ThreadID thread)
Definition: thread_management.h:72
Definition: thread_management.h:35
void join(ThreadID thread)
Definition: thread_management.h:62
void fork(ThreadFunc func, ThreadFuncArg *arg, ThreadID *thread)
Definition: thread_management.h:50