POSIX thread functions and errno

Posted on 2007-08-04
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?
Question by:chsalvia
    LVL 43

    Accepted Solution

    LVL 86

    Expert Comment

    'errno' - for it's very nature as a global variable - is not thread-safe ( From that conclusion, I would not even expect pthreads to use it in the 1st place.
    LVL 43

    Expert Comment

    In fact errno is usually thread safe. At least under Linux is.
    But true, there was a time when it werent.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    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 ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now