?
Solved

POSIX thread functions and errno

Posted on 2007-08-04
3
Medium Priority
?
694 Views
Last Modified: 2008-02-01
Do POSIX thread functions (e.g. pthread_create, pthread_join, etc) set errno if they fail?

Unlike most standard C functions or system calls, pthread functions return an integer corresponding to an error number, rather than returning -1 to inidcate an error.  The man pages for pthread functions conspicuously avoid saying that errno will be set if an error occurs.  However, a test program I created seems to indicate that pthread functions actually *do* set errno if there is an error, as well as returning an integer corresponding to the error.

But since the man pages do not explicitly say that pthread functions set errno, and also since there is another mechanism in place to report errors for pthread functions, I suspect that I shouldn't rely on pthread functions setting errno when it comes to portability.  Perhaps this is not standard.

Does anyone know?
0
Comment
Question by:chsalvia
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
ravenpl earned 1000 total points
ID: 19630385
0
 
LVL 86

Expert Comment

by:jkr
ID: 19630858
'errno' - for it's very nature as a global variable - is not thread-safe (http://en.wikipedia.org/wiki/Thread_safe#Identification). From that conclusion, I would not even expect pthreads to use it in the 1st place.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 19630898
In fact errno is usually thread safe. At least under Linux is.
But true, there was a time when it werent.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question