标签:
#include <stdio.h> #include <iostream> #include "unistd.h" #include "assert.h" #include <stdlib.h> #include "sys/wait.h" #include <pthread.h> pthread_t ntid; void printids(std::string s){ pid_t pid; pthread_t tid; pid = getpid(); tid = pthread_self(); printf("%s pid = %u tid = %u(hexadecimal) , (0x%x))\n", s.c_str(), (unsigned int)pid, (unsigned int)tid, (unsigned int)tid); } void* thr_callback(void* arg){ sleep(20); printids("new thread:"); return 0; } int main(int argc, char* argv[]){ int err; err = pthread_create(&ntid, NULL, thr_callback, NULL); if(err != 0) printf("can‘t create thread, error code: %d\n", err); printids("main thread:"); sleep(10); pthread_exit(0); }
标签:
原文地址:http://www.cnblogs.com/alazalazalaz/p/4379624.html