pthreads函数是否在内部设置了errno?

Gou*_*ham 4 c linux pthreads

在下面的代码中,我调用pthread_join(),其中线程ID为self.结果是它返回错误号35.所以同样我试图用perror打印.但它显示出"成功".我怀疑是库/系统调用是否需要明确地为任何错误设置errno或者我是否错过任何东西?

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>

#define DEATH(mess) { perror(mess); exit(errno); }

static void * threadFunc(void *arg)
{
 void *res;
 printf("sleeping for 2 sec ...\n");
 sleep(2);
 char *s = (char *) arg;
 pthread_t t = pthread_self();
 int relval = pthread_join(t, &res);

 if (relval) 
  perror("deadlock");

  printf("return value is %d .....\n",relval);
  return (void *) strlen(s);
}

int main(int argc, char *argv[])
{
 pthread_t t1;
 void *res;
 int ret;

 ret = pthread_create(&t1, NULL, threadFunc, "Hello world\n");
 if (ret != 0)
    DEATH ("pthread_create");

 printf("Message from main()\n");

 pthread_exit(&res);
 exit(EXIT_SUCCESS);
Run Code Online (Sandbox Code Playgroud)

}

o/p

Message from main()
sleeping for 2 sec ...
deadlock: Success
return value is 35 .....
Run Code Online (Sandbox Code Playgroud)

R..*_*R.. 7

没有要求thesr功能设置errno或他们不管它.你总是可以自由地做:

errno = pthread_join(t, &res);
Run Code Online (Sandbox Code Playgroud)