Tobiahao

S01_WATKI_06

Dec 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. /*
  2. Zademonstruj dziaΕ‚anie funkcji sigwait()
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <pthread.h>
  8. #include <signal.h>
  9. #include <unistd.h>
  10.  
  11. void *thread_function(void *p)
  12. {
  13.     static sigset_t set;
  14.     int sig;
  15.    
  16.     printf("Oczekiwanie na sygnal: \n");
  17.  
  18.     sigemptyset(&set);
  19.     if(sigaddset(&set, SIGUSR1) == -1){
  20.         perror("sigaddset");
  21.         return (void *)EXIT_FAILURE;
  22.     }
  23.  
  24.     if(sigwait(&set, &sig) != SIGUSR1){
  25.         perror("sigwait");
  26.         return (void *)EXIT_FAILURE;
  27.     }
  28.  
  29.     return EXIT_SUCCESS;
  30. }
  31.  
  32. int main(void)
  33. {
  34.     pthread_t thread;
  35.  
  36.     pthread_create(&thread, NULL, thread_function, (void *)NULL);
  37.  
  38.     sleep(2);
  39.  
  40.     pthread_kill(thread, SIGUSR1);
  41.     pthread_join(thread, NULL);
  42.  
  43.     return EXIT_SUCCESS;
  44. }
Add Comment
Please, Sign In to add comment