Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <pthread.h>
- void *wyslij(void* arg){
- int i,x;
- int fid = open("fifo12",0666);
- for(i = 0; i<10;i++){
- int* qid = (int*) arg;
- x = (rand() % 10);
- write(fid,&x,4);
- }
- }
- void *odbierz(void* arg){
- int i,s,buf = 0;
- int fid = open("fifo12",0666);
- for(i = 0;i<10;i++){
- read(fid,&buf,4);
- s += buf;
- }
- close(fid);
- fid = open("fifo23",0666);
- write(fid,&s,4);
- }
- void *pokaz(void* arg){
- int buf;
- int fid = open("fifo23",0666);
- read(fid,&buf,4);
- printf("%d\n",buf);
- close(fid);
- }
- int main(){
- srand(4324);
- mkfifo("fifo12",0666);
- mkfifo("fifo23",0666);
- pthread_t w,o,p;
- pthread_create(&w,NULL,wyslij,NULL);
- pthread_create(&o,NULL,odbierz,NULL);
- pthread_create(&p,NULL,pokaz,NULL);
- pthread_join(w,NULL);
- pthread_join(o,NULL);
- pthread_join(p,NULL);
- unlink("./fifo12");
- unlink("./fifo23");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment