Given the following:
pthread_t thread;
pthread_create(&thread, NULL, function, NULL);
-
What exactly does
pthread_createdo tothread? -
What happens to
threadafter it has joined the main thread and terminated? -
What happens if, after
threadhas joined, you do this:pthread_create(&thread, NULL, another_function, NULL);
threadis an object, it can hold a value to identify a thread. Ifpthread_createsucceeds, it fills in a value that identifies the newly-created thread. If it fails, then the value ofthreadafter the call is undefined. (reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_create.html)Nothing happens to the object, but the value it holds no longer refers to any thread (so for example you can no longer pass it to functions that take a
pthread_t, and if you accidentally do then you might getESRCHerrors back).Same as before: if
pthread_createsucceeds, a value is assigned that identifies the newly-created thread.