Pthread Join Error Code 3
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Pthread Error Code 22
and policies of this site About Us Learn more about Stack Overflow pthread_join example the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation pthread_join c Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it
Edeadlk
only takes a minute: Sign up How do I get the error code from pthread_join up vote 2 down vote favorite The following code fails to create join pthreads and the message "join failed" is printed. How do I get more information about the failure and it's cause? pthread_t aThread[MAX_LENGTH]; int errCode[MAX_LENGTH]; char returnVal; for(int i = 0; i <
What Does Pthread_join Do
MAX_LENGTH; i++) { if((errCode[i] = pthread_create(&aThread[i], NULL, &findMatch, &fpArgs)) != 0) printf("error creating thread %d\n", errCode[i]); if(!pthread_join(aThread[i], (void**)&returnVal)) printf("join failed\n i is %d", i); } EDIT: actually join returned no error and I made a mistake. The if statment shouldn't have the ! because join returns a non-zero number if there is a problem which evaluates to true. c pthreads pthread-join share|improve this question edited Oct 10 '13 at 4:44 asked Oct 10 '13 at 3:44 Celeritas 3,9611256111 1 Your cast of your returnVal address to a void** is undefined behavior. Unless sizeof(char) == sizeof(void*) on your system (which I can all-but-guarantee you it is not) It doesn't look like you're using it anyway, and NULL is a viable option, so you may rather just pthread_join(aThread[i], NULL); Further, pthread_join returns zero (0) on success, so testing it for failure with ! is backwards. Finally, you don't want to do it this way anyway, you want to start them all, then join them all. What you have here is literally no better than single threaded. –WhozCraig Oct 10
top pthread_join - join with a terminated thread SYNOPSIS top #include
to the Single Unix Specification standard consisted to submit an example of use for pthread_sigmask()[1]. Since my proposal was going to be viewed by many Austin Group's contributors (some being "recognized UNIX authority"), I tried to make my example as perfect as possible. In an academic fashion, I checked every function's return code for possible errors. That's where I got it wrong for the Pthreads APIs. Oh well, they do not use errno… The Problem: Before the advent of Pthreads, POSIX functions used to return -1 on error, and set the corresponding error code in the global variable errno[2]. This mechanism has a few drawbacks even for single-threaded process: it is not simple to return -1 as valid value. a signal handler may change the errno value between the point a function set errno, and the point where you check the errno variable. Of course, a global errno doesn't work for multi-threaded processes. Indeed, a thread could execute a function that modifies errno just before you check the value in another thread. The (Pthreads) Solution: Since Pthreads, the errno variable is thread-local. That is, every thread has its own "errno copy". If you (or a system function) set the errno variable in one thread, it won't affect the errno value in any other thread. This is shown in the example below. Download errno_01.c1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 /*------------------------------ errno_01.c -------------------------------* compile with: cc -pthread errno_01.c -o errno_01 Copyright Loic Domaigne. Licensed under the Apache License, Version 2.0. *--------------------------------------------------------------------------*/ #include