//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;
}
June 16th Tuesday (六月 十六日 火曜日)
最新推荐文章于 2025-05-31 23:29:16 发布