Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int in, out1,out2,out3,out4 = 0;
- int out[4];
- int buf[N];
- int read[N];
- semaphore n = 0,e=N ,s=1, priority=1;
- append{
- wait(priority);
- wait(e);
- wait(s);
- buf[in] = value;
- read[in] = 4;// assuer que la donner est acceder par les 4 consomateurs
- in = (in+1) % N;
- signal(s);
- signal(n);
- signal(priority);
- }
- take(int procressId){
- wait(priority); //attendre qu les producteurs terminent leur traitement
- signal(priority);
- int message;
- wait(n);
- wait(s);
- message = buf[out[processId]];
- read[ out[processId]] --;
- if (read[out[processId]] == 0){
- signal(e); // notify les producteurs
- buf[out[processId]] = Null; // free data
- }
- out[processId] = (out[processId] + 1) % N;
- signal(s);
- }
Advertisement
Add Comment
Please, Sign In to add comment