Matt23

Threads zad 1

May 24th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <stdio.h>
  3.  
  4. long counter = 0;
  5.  
  6. void* printCounter() {
  7.     while (1) {
  8.         printf("%ld\n", counter);
  9.     }
  10. }
  11.  
  12. void* incrementCounter() {
  13.     while (1) {
  14.         counter++;
  15.     }
  16. }
  17.  
  18. int main() {
  19.     pthread_t printer, incrementer;
  20.     pthread_create(&printer, NULL, printCounter, NULL);
  21.     pthread_create(&incrementer, NULL, incrementCounter, NULL);
  22.    
  23.     pthread_join(incrementer, NULL);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment