2008-02-13 20:57:46 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#define NUM_THREADS 5
|
|
|
|
|
|
|
|
void *PrintHello(void *threadid)
|
|
|
|
{
|
2010-03-04 22:14:37 +00:00
|
|
|
int tid = (int)threadid;
|
2008-02-13 20:57:46 +00:00
|
|
|
printf("Hello World! It's me, thread #%d!\n", tid);
|
2010-03-04 22:14:37 +00:00
|
|
|
sleep(2); // keep this thread around for a bit; the tests will check for its existence while the main thread is stopped at a breakpoint
|
2008-02-13 20:57:46 +00:00
|
|
|
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("In main: 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);
|
|
|
|
}
|
|
|
|
|