//pool.cpp
1 #include <iostream>
#include <stdio.h>
#include <pthread.h>
#include "pool.h"
using namespace std;
pool::pool()
{
cout << "pool()" << endl;
}
pool::~pool()
{
cout << "~pool()" << endl;
}
void pool::func(){
cout << "pool::func" << endl;
}
//void *pool::schedule(void *ptr){
void *pool::schedule(void *ptr){
cout << "enter pool::schedule" << endl;
//unjoinable属性可以在pthread_create时指定,或在线程创建后在线程中pthread_detach自己,
int res = pthread_detach(pthread_self());
if(res != ){
printf("please check /proc/%ld/maps\n", pthread_self());
}
pool *p = (pool *)ptr;
p->func();
cout << "leave schedule" << endl;
return ;
}
int pool::schedule_thread(){
cout << "enter pool::schedule_thread" << endl;
pthread_t pid;
//if(pthread_create(&pid , NULL ,schedule, (void *)this) != 0){
if(pthread_create(&pid , NULL ,schedule, (void *)this) != ){
cerr << "schedule thread create fail" << endl;
return -;
}
cout << "leave pool::schedule_thread" << endl;
return ;
}