Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gcc -g -o -pthread
- #include <stdio.h>
- #include <unistd.h>
- #include <pthread.h>
- #include <time.h>
- #include <signal.h>
- void *dot(void *b) {
- puts(".");
- return NULL;
- }
- void *time1(void *a) {
- time_t sekund;
- struct tm *wsk_strukt;
- char napis[100];
- for (int i = 1; i <= 60; i++) {
- time(&sekund);
- wsk_strukt = localtime(&sekund);
- strftime(napis, 100, "%H:%M:%S", wsk_strukt); // tylko godzina, minuta, sekunda
- //strftime (napis, 100, "%c", wsk_strukt); // tutaj %c oznacza datΔ i czas
- puts(napis);
- sleep(1);
- }
- return NULL;
- }
- int main() {
- pthread_t t0, t1; //deklaracja watkow
- void *result;
- if (pthread_create(&t0, NULL, time1, NULL) == -1); // pierwszy watek
- while ((pthread_kill(t0, 0)) == 0) { // dopoki 1 watek sie nie skonczy
- if (pthread_create(&t1, NULL, dot, NULL) == -1); // tworzenie drugiego watku
- sleep(5);
- }
- if (pthread_join(t0, &result) == -1); // zakonczenie 1 watku
- if (pthread_join(t1, &result) == -1) // zakonczenie 2 watku
- sleep(61);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement