Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Plain Text by 12123 ( 12 years ago )
/*Illustrates: thread creation, thread joining. */
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include "pthread.h"
void * process (void * arg)
{
int i;
printf("Starting process %s\n", (char *) arg);
for (i = 0; i < 1000; i++) {
printf((char *) arg);
};
return NULL;
}
int main(void)
{
int retcode;
pthread_t th_a, th_b, th_c, th_d, th_e, th_f, th_g, th_h;
void * retval;
retcode = pthread_create(&th;_a, NULL, process, (void *) "a");
retcode = pthread_create(&th;_b, NULL, process, (void *) "b");
retcode = pthread_create(&th;_c, NULL, process, (void *) "c");
retcode = pthread_create(&th;_d, NULL, process, (void *) "d");
retcode = pthread_join(th_a, &retval;);
retcode = pthread_join(th_b, &retval;);
retcode = pthread_create(&th;_e, NULL, process, (void *) "e");
retcode = pthread_join(th_e, &retval;);
retcode = pthread_join(th_c, &retval;);
retcode = pthread_join(th_d, &retval;);
retcode = pthread_create(&th;_f, NULL, process, (void *) "f");
retcode = pthread_create(&th;_g, NULL, process, (void *) "g");
retcode = pthread_create(&th;_h, NULL, process, (void *) "h");
retcode = pthread_join(th_f, &retval;);
retcode = pthread_join(th_g, &retval;);
retcode = pthread_join(th_h, &retval;);
return 0;
}
Revise this Paste