Tobiahao

S01_WATKI_01

Dec 19th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. /*
  2. Stwórz w programie dwa wątki, które wypiszą swój identyfikator i identyfikator procesu.
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <pthread.h>
  8. #include <unistd.h>
  9.  
  10. void *first_thread_func()
  11. {
  12.     printf("Watek 1: Id watku: %lu Id procesu: %d\n", pthread_self(), getpid());
  13.     return EXIT_SUCCESS;
  14. }
  15.  
  16. void *second_thread_func()
  17. {
  18.     printf("Watek 2: Id watku: %lu Id procesu: %d\n", pthread_self(), getpid());
  19.     return EXIT_SUCCESS;
  20. }
  21.  
  22. int main(void)
  23. {
  24.     pthread_t first_thread, second_thread;
  25.  
  26.     pthread_create(&first_thread, NULL, first_thread_func, (void *)0);
  27.     pthread_create(&second_thread, NULL, second_thread_func, (void *)0);
  28.  
  29.     pthread_join(first_thread, NULL);
  30.     pthread_join(second_thread, NULL);
  31.  
  32.     return EXIT_SUCCESS;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment