#include <pthread.h>
#include <unistd.h>
#include <iostream>
using namespace std;
void* handle(void* p){
int* pn = (int*)p;
for(int i=0;i<20;++i){
sleep(1);
cout << pthread_self() << ":" << --*pn << endl;
}
delete pn;
// pthread_exit();
return NULL;
}
pthread_t test(){
//int n = 0;
int* p = new int(0);
pthread_t tid;
pthread_create(&tid,NULL,handle,p);
return tid;
}
int main(){
cout << getpid() << endl;
cout << pthread_self() << endl;
// sleep(100);
pthread_t tid = test();
int n = 0;
// pthread_detach(tid);
for(int i=0;i<10;++i){
sleep(1);
cout << pthread_self() << ":" << ++n << endl;
}
pthread_join(tid,NULL);
return 0;
}