June 16th Tuesday (六月 十六日 火曜日)
2009-06-26 20:51
363 查看
//GThread.cpp
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <iostream>
using namespace std;
class GThread {
private:
pthread_t _thread;
void * (*_routine)(void *);
void * _arg;
public:
GThread(void * (*start_routine)(void *), void * arg) {
memset(&_thread, 0, sizeof(pthread_t));
_routine = start_routine;
_arg = arg;
}
~GThread() {
//pthread_detach(_thread);
memset(&_thread, 0, sizeof(pthread_t));
_routine = NULL;
_arg = NULL;
}
void start() {
if (_routine) {
pthread_create(&_thread, NULL, _routine, _arg);
}
}
void suspend() {
}
void resume() {
}
};
void * test(void *arg){
int *np = (int *)arg;
cout<<"thread no. "<<(*np)<<endl;
return NULL;
}
int main() {
int thread_no[3] = {1, 2, 3};
//for (int i = 0; i < 3; i++) {
GThread gt(test, &thread_no[0]);
gt.start();
//}
return 0;
}
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <iostream>
using namespace std;
class GThread {
private:
pthread_t _thread;
void * (*_routine)(void *);
void * _arg;
public:
GThread(void * (*start_routine)(void *), void * arg) {
memset(&_thread, 0, sizeof(pthread_t));
_routine = start_routine;
_arg = arg;
}
~GThread() {
//pthread_detach(_thread);
memset(&_thread, 0, sizeof(pthread_t));
_routine = NULL;
_arg = NULL;
}
void start() {
if (_routine) {
pthread_create(&_thread, NULL, _routine, _arg);
}
}
void suspend() {
}
void resume() {
}
};
void * test(void *arg){
int *np = (int *)arg;
cout<<"thread no. "<<(*np)<<endl;
return NULL;
}
int main() {
int thread_no[3] = {1, 2, 3};
//for (int i = 0; i < 3; i++) {
GThread gt(test, &thread_no[0]);
gt.start();
//}
return 0;
}
相关文章推荐
- June 2nd Tuesday (六月 二日 火曜日)
- June 12th Tuesday (六月 十二日 火曜日)
- June 30th Tuesday (六月 三十日 火曜日)
- June 26th Tuesday (六月 二十六日 火曜日)
- 2008 September 16th Tuesday (九月 十六日 火曜日)
- June 5th Tuesday (六月 五日 火曜日)
- June 19th Tuesday (六月 十九日 火曜日)
- June 9th Tuesday (六月 九日 火曜日)
- June 23th Tuesday (六月 二十三日 火曜日)
- June 18th Tuesday (六月 十八日 木曜日)
- Februray 27th Tuesday (一月 二十七日 火曜日)
- March 27th Tuesday (三月 二十七日 火曜日)
- May 8th Tuesday (五月 八日 火曜日)
- June 7th Thursday (六月 七日 木曜日)
- June 20th Wednesday (六月 二十日 水曜日)
- August 14th Tuesday (八月 十四日 火曜日)
- December 25th Tuesday (十二月 二十五日 火曜日)
- 2008 January 8th Tuesday (一月 八日 火曜日)
- 2008 March 11th Tuesday (三月 十一日 火曜日)
- 2008 April 15th Tuesday (四月 十五日 火曜日)