Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The thread id is definitely written before <code>pthread_create</code> returns. If you think about it, it would be impossible for <code>pthread_create</code> to work any other way. It could not delegate writing the thread id to the new thread, because the <code>pthread_t</code> variable might be out of scope by the time the new thread runs.</p> <p>The relevant text is:</p> <blockquote> <p>Upon successful completion, pthread_create() shall store the ID of the created thread in the location referenced by thread.</p> </blockquote> <p>(From <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html" rel="nofollow">http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html</a>) Note that it says "on successful completion" of the function, not "at an indeterminate time after successful completion".</p> <p>The more interesting question, and I'm unclear on this one, is whether <code>pthread_create</code> must have finished writing the thread id to its destination before the new thread start function begins, i.e. whether the new thread can immediately see its own thread id, e.g. if it's to be stored in a global variable. I suspect the answer is no.</p> <p><strong>Edit:</strong> Upon rereading your question, it seems like you might really have been asking about this latter, more interesting question. In any case, there's no reason for the new thread's start function to use the thread-id written out by <code>pthread_create</code>. Your new thread can (and should) just use <code>pthread_self</code> to get its own thread id.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload