Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
When the main thread completes, all the child threads are terminated and their resources freed. We can see this demonstrated if we build and run the code shown in Listing 5.15.
#include <pthread.h>
#include <stdio.h>
void* thread_code( void * param )
{
printf( "In thread code\n" );
}
int main()
{
pthread_t thread;
pthread_create( &thread, 0, &thread_code, 0 );
printf( "In main thread\n" );
} |