c - Does the pthreads functions set the errno internally? -
in below code calling pthread_join() thread id self. result returns error number 35. same trying print perror. displaying "success". uncertainty library/system calls need explictly set errno errors or did miss thing ?
#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 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 %d .....\n",relval); homecoming (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 main()\n"); pthread_exit(&res); exit(exit_success);
}
o/p message main() sleeping 2 sec ... deadlock: success homecoming value 35 .....
there no requirement thesr functions set errno
or leave alone. you're free do:
errno = pthread_join(t, &res);
c linux pthreads
No comments:
Post a Comment