Advertisement
willtrieagain

Untitled

Oct 10th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<pthread.h>
  3. #include<stdlib.h>
  4. #include<unistd.h>
  5.  
  6. typedef struct s {
  7. int a;
  8. int b;
  9. int sum;
  10. } s;
  11.  
  12. void* sum(void* inp) {
  13. s* inputs = (s*)inp;
  14. int a = inputs -> a;
  15. int b = inputs -> b;
  16. inputs -> sum = a+b;
  17. sleep(3);
  18. return NULL;
  19. }
  20.  
  21. int main() {
  22. pthread_t tid;
  23. s* operands = (s*)malloc(sizeof(s));
  24. operands->a = 1;
  25. operands->b = 1;
  26.  
  27. pthread_create(&tid, NULL, sum, (void*)(operands));
  28.  
  29. pthread_join(tid, NULL);
  30.  
  31. printf("%d\n", operands->sum);
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement