Advertisement
bcolan

2dretve iz jednog procesa

Feb 17th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <sys/wait.h>
  6. /*2dretve nastale iz jednog procesa*/
  7. using namespace std;
  8.  
  9. pthread_t  dr[2];
  10.  
  11. void *dretva(void *)
  12. {
  13.     cout << "Book iz dretve!"<<endl;
  14. }
  15.  
  16. void proces()
  17. {
  18.     for(int i = 0; i < 2 ; i++){
  19.         pthread_create(&dr[i],NULL,dretva,NULL);
  20.     }
  21.     for(int i = 0; i < 2 ; i++){
  22.         pthread_join(dr[i],NULL);
  23.     }
  24.    
  25.        
  26.     cout << "Bok iz procesa!"<<endl;
  27.  
  28. }
  29.  
  30. int main(){
  31.    
  32.     if(fork()==0)
  33.     {
  34.        proces();
  35.        exit(0);
  36.     }
  37.     wait(NULL);
  38.    
  39.     return 0;
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement