/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗ FILE: hello.c

∗ DESCRIPTION:

∗ A ”hello world” Pthreads program. Demonstrates thread creation and

∗ termination. ∗

∗ SOURCE:

∗ LAST REVISED: 9/20/98 Blaise Barney ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

#include <pthread.h>
#include <stdio.h>

#define NUM THREADS 5

void ∗ PrintHello( void ∗threadid ) {

printf( "\n%d: Hello World!\n", threadid ); pthread exit( NULL );

}

int main( int argc, char ∗argv[] ) {

pthread t threads[NUM THREADS];

int rc, t;

for ( t = 0; t < NUM THREADS; t++ ) {

               printf( "Creating thread %d\n", t );

rc = pthread create( &threads[t], NULL, PrintHello,

( void ∗ ) &t );

if ( rc ) {

printf

                           ( "ERROR; return code from pthread create() is
%d\n",

rc ); exit( −1 );

}

}

pthread exit( NULL );

}