MarVin666

Threads SO 1 zad

Apr 11th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4.  
  5.     volatile  int licznik;
  6.  
  7. void *print_message_function( void *ptr )
  8. {
  9.      char *message;
  10.      message = (char *) ptr;
  11.      printf("%s \n", message);
  12. }
  13.  
  14. void *elo();
  15.  
  16. void *elo1()
  17. {
  18.         while(1)
  19.         {
  20.             licznik++;
  21.         }
  22. }
  23.  
  24. int main()
  25. {
  26.      pthread_t thread1, thread2;
  27.      const char *message1 = "Thread 1";
  28.      const char *message2 = "Thread 2";
  29.      int  iret1, iret2;
  30.  
  31.  
  32.     /* Create independent threads each of which will execute function */
  33.  
  34.      iret1 = pthread_create( &thread1, NULL, elo, (void*) message1);
  35.      iret2 = pthread_create( &thread2, NULL, elo1, (void*) message2);
  36.  
  37.      pthread_join( thread1, NULL);
  38.      pthread_join( thread2, NULL);
  39.  
  40.      exit(EXIT_SUCCESS);
  41. }
  42.  
  43. void *elo()
  44. {
  45.     while(1)
  46.     {
  47.         printf("Elo  %d \n", licznik);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment