Advertisement
Guest User

tu lab 7 zad 4

a guest
Jun 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <sys/types.h>
  2.  
  3. #include <sys/stat.h>
  4.  
  5. #include <fcntl.h>
  6.  
  7. #include <pthread.h>
  8.  
  9. #include <string.h>
  10.  
  11. #include <sys/file.h>
  12.  
  13. #include <stdlib.h>
  14.  
  15. #include <stdio.h>
  16.  
  17. #include <unistd.h>
  18.  
  19. #include <time.h>
  20.  
  21.  
  22.  
  23.  
  24.  
  25. void *fun_watek1(void * p);
  26.  
  27. void *fun_watek2(void * p);
  28.  
  29.  
  30.  
  31. char* message;
  32.  
  33.  
  34.  
  35. pthread_attr_t attr;
  36.  
  37.  
  38.  
  39. int main() {
  40.  
  41.  
  42.  
  43. pthread_t watek1;
  44.  
  45. pthread_t watek2;
  46.  
  47.  
  48.  
  49. pthread_attr_init(&attr);
  50.  
  51.  
  52.  
  53. pthread_create(&watek1, &attr, fun_watek1, (void *)&message);
  54.  
  55.  
  56.  
  57. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  58.  
  59. pthread_create(&watek2, &attr, fun_watek2, (void *)&message);
  60.  
  61.  
  62.  
  63. pthread_join(watek1, NULL);
  64.  
  65. //tu
  66.  
  67. pthread_join(watek2, NULL);
  68.  
  69.  
  70.  
  71. pthread_attr_destroy(&attr);
  72.  
  73. return0;
  74.  
  75. }
  76.  
  77.  
  78.  
  79. void *fun_watek1(void * p) {
  80.  
  81. printf("Watek 1: %lu, PID: %d\n", pthread_self(), getpid());
  82.  
  83.  
  84.  
  85. return0;
  86.  
  87. }
  88.  
  89.  
  90.  
  91. void *fun_watek2(void * p) {
  92.  
  93. printf("Watek 2: %lu, PID: %d\n", pthread_self(), getpid());
  94.  
  95.  
  96.  
  97. return0;
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement