Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. void* show(void* a)
  6. {
  7. int* suma=malloc(sizeof(int));
  8. int *b=(int*)a;
  9. for (int i=0;i<*b;i++)
  10. {
  11. *suma+=i;
  12. printf("%d ",i);
  13. usleep(10000);
  14. }
  15. printf("\n");
  16. return (void*)suma;
  17. }
  18. int main(void) {
  19. int* sum;
  20. int* sum2;
  21. int a=8;
  22. pthread_t thread_1,thread_2;
  23. pthread_create(&thread_1,NULL,show,(void*)&a);
  24. int b=7;
  25. pthread_create(&thread_2,NULL,show,(void*)&b);
  26. pthread_join(thread_1, (void**)&sum);
  27. pthread_join(thread_2, (void**)&sum2);
  28. printf("%d %d",*sum,*sum2);
  29. free(sum);
  30. free(sum2);
  31. //show();
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement