#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
void printId(const char* s)
{
pid_t pid = getpid();
pthread_t tid = pthread_self();
printf("%s pid %u tid %u (0x%x)\n",s,(unsigned int)pid,(unsigned int)tid,(unsigned int)tid);
}
void* testThread(void* /*p*/)
{
printId("new thread:");
//将返回值传出
pthread_exit((void*)"thread finished");
return 0;
}
int main()
{
pthread_t pid;
pthread_create(&pid,NULL,testThread,NULL);
void* ret = NULL;
pthread_join(pid,&ret);
printId("main thread:");
printf("ret:%s",(char*)ret);
}
new thread: pid 20959 tid 3077462896 (0xb76e5b70)
main thread: pid 20959 tid 3077469904 (0xb76e76d0)
ret:thread finished
线程返回值传出
最新推荐文章于 2022-05-30 01:37:38 发布