Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Zadanie 1
- Kod:
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <unistd.h>
- void* Funkcja(void* arg) //watek 2
- {
- while(1)
- {
- printf("Watek 1 ma id: %d\n",pthread_self());
- fflush(stdout);
- sleep(1);
- sleep(10);
- }
- return(0);
- }
- int main(void) //watek 1
- {
- pthread_t watek_2;
- //getchar();
- pthread_create(&watek_2,NULL,Funkcja,NULL);
- //while(1)
- //{
- printf("Watek 2 ma id: %d\n",pthread_self());
- fflush(stdout);
- sleep(1);
- //}
- return(0);
- }
- Zadanie 2
- Kod:
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <unistd.h>
- void* Funkcja(void* arg) //watek 2
- {
- printf("Watek 1 ma id: %d\n",pthread_self());
- fflush(stdout);
- sleep(1);
- //sleep(4);
- pthread_exit(0);
- }
- int main(void) //watek 1
- {
- pthread_t watek_2;
- pthread_create(&watek_2,NULL,Funkcja,NULL);
- printf("Watek 2 ma id: %d\n",pthread_self());
- fflush(stdout);
- sleep(5);
- pthread_join(watek_2,NULL);
- return(0);
- }
- Zadanie 3
- Kod:
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <unistd.h>
- void* Funkcja(int* arg) //watek 2
- {
- int cyfra;
- /
- printf("Watek 1 ma id: %d\n",pthread_self());
- fflush(stdout);
- cyfra=*arg;
- cyfra=cyfra*cyfra;
- pthread_exit(cyfra);
- }
- int main(void) //watek 1
- {
- int cyfra, wynik, wynik_2;
- pthread_t watek_2;
- printf("Watek 2 ma id: %d\n",pthread_self());
- fflush(stdout);
- scanf("%d",&cyfra);
- pthread_create(&watek_2,NULL,&Funkcja,&cyfra);
- pthread_join(watek_2,&wynik_2);
- wynik = wynik_2;
- printf("Wynik: %d\n",wynik);
- fflush(stdout);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement