Does pthread_create set the thread ID before the new thread executes?
Wan-Teh Chang wrote: > The first argument for pthread_create() is the address of a pthread_t > variable in which pthread_create() will write the new thread’s ID before > it returns. > > But it’s not clear whether the new thread’s ID is written into the > pthread_t > variable before the new thread begins to run. The POSIX standard implies that the ID will not be set before the thread is scheduled. The actual text is “Upon successful completion, pthread_create shall store the ID of the created thread […].” You always need to remember, in any case, that threads operate asynchronously, and one great way to hammer that message home is to prevent anyone from counting on basics like having the create’s ID when the thread starts. (Yeah, that sounds mean, and I guess it is. But way back in the early days of threading, when nobody know much about using threads, and people yelled “I don’t want to use synchronization, so you need to give me non-preemptive thread scheduling!”, we faced a really b