Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9148295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:14:01+00:00 2026-06-17T11:14:01+00:00

I was asked from where do we know that when passing NULL as a

  • 0

I was asked from where do we know that when passing NULL as a second argument in pthread_create() function the thread is made joinable.

I mean, I know that man pages state so, but a justification in code was demanded.
I know that when NULL is passed in, default attributes are used:

const struct pthread_attr *iattr = (struct pthread_attr *) attr;
if (iattr == NULL)
/* Is this the best idea? On NUMA machines this could mean accessing far-away memory. */
iattr = &default_attr;

I know that it should be somewhere in the code of pthread library, but I don’t know where exactly.

I know that the definition of default_attr is in pthread_create.c:

static const struct pthread_attr default_attr = { /* Just some value > 0 which gets rounded to the nearest page size. */ .guardsize = 1, };

http://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_create.c;h=4fe0755079e5491ad360c3b4f26c182543a0bd6e;hb=HEAD#l457

but I do not know where is exactly stated in the code that this result in a joinable thread.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:14:02+00:00Added an answer on June 17, 2026 at 11:14 am

    First off, from the code you pasted you can see that default_attr contains zeroes in almost all fields (there’s no such thing as a half-initialized variable in C: if you only initialize some fields, the others are set to 0).

    Second, pthread_create contains this code:

    /* Initialize the field for the ID of the thread which is waiting
       for us.  This is a self-reference in case the thread is created
       detached.  */
    pd->joinid = iattr->flags & ATTR_FLAG_DETACHSTATE ? pd : NULL;
    

    This line checks whether iattr->flags has the ATTR_FLAG_DETACHSTATE bit set, which (for default_attr) it doesn’t because default_attr.flags is 0. Thus it sets pd->joinid to NULL and not to pd as for detached threads.

    (Note that this answer only applies to GNU glibc and not to POSIX pthreads in general.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a question here about an Linq error that results from mixing Linq-To-SQL
I have been asked to write a script that pulls the latest code from
I know that this question might have been asked like 100 times, but, believe
I know that similar questions have been asked all over the place, but I'm
I know that this is a simple question and asked by many more many
I know that this type of question has been asked over and over again,
I know that this question has been asked quite a few times, but I
I know that this question has been asked many times before in different guises
OK, I KNOW that variations on this have been asked and answered; I've been
I know that it was asked for Reflection on ExpandoObjects here before. My question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.