ProvaPratica 2010.07.12

From Sistemi Operativi
Revision as of 22:41, 31 March 2014 by AlexJ (talk | contribs) (Created page with "<h1>http://www.cs.unibo.it/~renzo/so/compiti/2010-07-12.tot.pdf</h1> <syntaxhighlight lang="C"> monitor priocoop{ condition run[9]; int waiting[9]=0,0,0,0,0,0,0,0,0; int ma...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

http://www.cs.unibo.it/~renzo/so/compiti/2010-07-12.tot.pdf


monitor priocoop{
condition run[9];
int waiting[9]=0,0,0,0,0,0,0,0,0;
int maxprio=0;
int occupato=0;

procedure entry init(prio){	
	if(occupato==1)
	{
		if(maxprio < prio)
		{
		maxprio=prio;
		}
	waiting[prio]++;			
	run[prio].wait();
	waiting[prio]--;
	}
occupato=1;
}

procedure entry yield(prio){
run[maxprio].signal();
        if(maxprio < prio)
	{
	maxprio=prio;
	}
waiting[prio]++;
run[prio].wait();
waiting[prio]--;
}

procedure entry fini(prio){
int i;
occupato=0;
waiting[prio]--;
	if(waiting[maxprio] == 0)
	{
	maxprio=0;
		for(i=prio;i>=0;i--)
		{
			if(waiting[i]!=0)
			{
			maxprio=0;
			}
		}		
	run[maxprio].signal();
	}
}

Alessandro