Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <pthread.h>
- #include <unistd.h>
- #include <stdlib.h>
- void* show(void* a)
- {
- int* suma=malloc(sizeof(int));
- int *b=(int*)a;
- for (int i=0;i<*b;i++)
- {
- *suma+=i;
- printf("%d ",i);
- usleep(10000);
- }
- printf("\n");
- return (void*)suma;
- }
- int main(void) {
- int* sum;
- int* sum2;
- int a=8;
- pthread_t thread_1,thread_2;
- pthread_create(&thread_1,NULL,show,(void*)&a);
- int b=7;
- pthread_create(&thread_2,NULL,show,(void*)&b);
- pthread_join(thread_1, (void**)&sum);
- pthread_join(thread_2, (void**)&sum2);
- printf("%d %d",*sum,*sum2);
- free(sum);
- free(sum2);
- //show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement