#include #include #include #define NUM_THREADS 5 DWORD WINAPI print_hello( void *threadid ) { printf( "\n%d: Hello World!\n", threadid ); return 0; } int main() { static DWORD threads[ NUM_THREADS ]; static HANDLE handles[ NUM_THREADS ]; unsigned int t; for ( t = 0; t < NUM_THREADS; ++t ) { printf( "Creating thread %d\n", t ); handles[ t ] = CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE ) print_hello, ( LPVOID ) t, 0, (LPDWORD) &threads[ t ] ); if ( ! handles[ t ] ) { printf( "Error: failed to create thread %d\n", t ); exit( 1 ); } } WaitForMultipleObjects( NUM_THREADS, handles, 1, INFINITE ); return 0; }