Advertisement
SIKER_98

123345

Dec 8th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // gcc -g -o -pthread
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <pthread.h>
  5. #include <time.h>
  6. #include <signal.h>
  7.  
  8. void *dot(void *b) {
  9. puts(".");
  10. return NULL;
  11. }
  12.  
  13. void *time1(void *a) {
  14.  
  15. time_t sekund;
  16. struct tm *wsk_strukt;
  17. char napis[100];
  18.  
  19. for (int i = 1; i <= 60; i++) {
  20. time(&sekund);
  21. wsk_strukt = localtime(&sekund);
  22. strftime(napis, 100, "%H:%M:%S", wsk_strukt); // tylko godzina, minuta, sekunda
  23. //strftime (napis, 100, "%c", wsk_strukt); // tutaj %c oznacza datΔ™ i czas
  24. puts(napis);
  25. sleep(1);
  26. }
  27. return NULL;
  28. }
  29.  
  30. int main() {
  31. pthread_t t0, t1; //deklaracja watkow
  32. void *result;
  33.  
  34. if (pthread_create(&t0, NULL, time1, NULL) == -1); // pierwszy watek
  35.  
  36. while ((pthread_kill(t0, 0)) == 0) { // dopoki 1 watek sie nie skonczy
  37.  
  38. if (pthread_create(&t1, NULL, dot, NULL) == -1); // tworzenie drugiego watku
  39. sleep(5);
  40. }
  41.  
  42.  
  43. if (pthread_join(t0, &result) == -1); // zakonczenie 1 watku
  44. if (pthread_join(t1, &result) == -1) // zakonczenie 2 watku
  45. sleep(61);
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement