#define NPRIO 10 sem_t wait[NPRIO]={0,0....}; int nBlockedPrio[NPRIO]={0,0,...}; int nBlocked=0; int pass = 0; int sem=2; sem_t sync=0; int p(int prio, int value_p){ int ret; P(m); if(sem==0){ nBlocked++; nBlockedPrio[prio]++; V(m); P(wait[prio]); ret=pass; pass=value_p; V(sync); return ret; }else{ sem--; V(m); return 0; } } int v(int value_v){ int ret; P(m); if(nBlocked){ for(i=NPRIO-1; i>=0; i--){ if (nBlockedPrio[i]){ nBlockedPrio[i]--; nBlocked--; pass = value_v; V(wait[i]); P(sync); ret=pass; V(m); return ret; } } }else{ sem++; V(m); return 0; } }