20 #include "threadexceptions.h"
33 void *my_thread_function(
void *param)
39 std::cout <<
"loop number: " << i << std::endl;
54 void *my_thread_function2(
void *param)
60 std::cout <<
"another loop number: " << i << std::endl;
75 void *my_thread_function3(
void *param)
78 int num_iter=*((
int *)param);
80 for(i=0;i<=num_iter;i++)
82 std::cout <<
"user defined loop number: " << i << std::endl;
161 int main(
int argc,
char *argv[])
164 std::string thread_id;
165 CThread Thread(
"test_thread"),*Thread2;
168 thread_id=Thread.
get_id();
169 std::cout <<
"Thread identifier: " << thread_id << std::endl;
172 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
173 Thread.attach(my_thread_function,NULL);
175 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
178 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
182 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
185 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
188 Thread.attach(my_thread_function2,NULL);
190 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
193 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
199 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
202 Thread.attach(my_thread_function3,&num_iter);
204 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
207 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
211 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
214 std::cout <<
"Thread state: " << Thread.get_state() << std::endl;
218 Thread.attach(NULL,NULL);
220 std::cout << e.
what() << std::endl;
225 std::cout << e.
what() << std::endl;
231 std::cout << e.
what() << std::endl;
virtual const std::string & what(void)
Function to get the error message.
Implementation of a parallel thread of execution.
std::string get_id(void)
Function to get the thread identifier.