您的位置:首页 > 产品设计 > UI/UE

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: