Advertisement
yudiwibisono

uas_thread

Jun 22nd, 2022
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>  
  4. #include <pthread.h>
  5.  
  6.  
  7. int data[5];  
  8.  
  9. void *fungsi1(void *vargp)
  10. {
  11.     printf("Isi dengan 1\n");
  12.     for (int i=0;i<=2;i++) data[i] = 1;
  13.     return NULL;
  14. }
  15.  
  16. void *fungsi2(void *vargp)
  17. {
  18.     printf("Isi dengan 2\n");
  19.     for (int i=3;i<=5;i++) data[i] = 2;
  20.     return NULL;
  21. }
  22.    
  23. int main()
  24. {
  25.     pthread_t thread_id1,thread_id2;
  26.  
  27.     pthread_create(&thread_id1, NULL, fungsi1, NULL);
  28.     pthread_join(thread_id1, NULL);
  29.  
  30.     pthread_create(&thread_id2, NULL, fungsi2, NULL);
  31.     pthread_join(thread_id2, NULL);
  32.  
  33.     for (int i=0;i<=5;i++) printf("Data: %d \n",data[i]);
  34.     exit(0);
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement