Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define NUM_THREADS 5
- void *perform_work(void *argument)
- {
- int passed_in_value;
- passed_in_value = *((int *) argument) ;
- printf ("Hello World! It's me.thread with arguent \d!\n", passed_in_value) ;
- }
- int main (void)
- {
- pthread_t threads[NUM_THREADS];
- int thread_args[NUM_THREADS];
- int result_code, index;
- for (index = 0; index < NUM_THREADS; ++index)
- {
- thread_args[index]= index;
- printf ("In main :creating thread %d\n", index);
- result_code = pthread_create(&threads[index], NULL, perform_work, (void *)&thread_args[index]);
- }
- for (index = 0; index < NUM_THREADS; ++index) {
- result_code = pthread_join(threads[index], NULL);
- printf ("In main :thread %d has cpleted\n", index);
- }
- printf("In main:All threads Completed successfully\n");
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement