- 论坛徽章:
- 0
|
请问这两个函数或系统调用是不是一回事?我这里它们的返回值是不等的。
比如下面这个程序:
- #define _GNU_SOURCE
- #include <stdio.h>
- #include <sys/types.h>
- #include <pthread.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/syscall.h>
- void *thsf(void *arg){
- pthread_t th;
- char *retstr;
- retstr=malloc(50);
- memset(retstr,0,50);
- strcpy(retstr,"New thread quit!");
- th=pthread_self();
- printf("New thread,pid:%d,tid:%x,another tid:%x.\n",getpid(),th,(long)syscall(SYS_gettid));
- pthread_exit(retstr);
- }
- int main(){
- pthread_t nth1,mth,oth;
- void *a;
- if(pthread_create(&nth1,NULL,thsf,NULL))
- printf("Error create new thread.\n");
- mth=pthread_self();
- printf("Main thread,pid:%d,tid:%x,another tid:%x.\n",getpid(),mth,(long)syscall(SYS_gettid));
- if(!pthread_join(nth1,&a)){
- printf("New thread quit,message from new thread:%s.\n",(char *)a);
- free((char *)a);
- }
- return 0;
- }
复制代码 |
|