Difference between revisions of "ProvaPratica 2010.07.12"

From Sistemi Operativi
Jump to navigation Jump to search
Line 100: Line 100:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
-Midolo
 
-Midolo
 +
 +
 +
 +
<syntaxhighlight lang="C">
 +
//0: priorita' maggiore
 +
//9: priorita' minore
 +
cond oktoenter[10];
 +
int count[10];
 +
bool running = false;
 +
 +
//restituisce la priorita' maggiore che ha un processo in attesa
 +
getprio() {
 +
      for(i=0;i<10;i++) {
 +
if(count[i]>0)
 +
break;
 +
}
 +
return i;
 +
}
 +
 +
priocoop() {
 +
init (prio) {
 +
if (running) {
 +
count[prio]++;
 +
oktoenter[prio].wait();
 +
count[prio]--;
 +
}
 +
running = true;
 +
}
 +
yield(prio) {
 +
i=getprio();
 +
if (i < 10) {
 +
// running = false;
 +
oktoenter[i].signal();
 +
count(prio)++
 +
oktoenter[proc].wait();
 +
                // running = true;
 +
                count[prio]--;
 +
}
 +
}
 +
fini(prio){
 +
i=getprio();
 +
running=false;
 +
if(i<10)
 +
oktoenter[i].signal;
 +
}
 +
}
 +
</syntaxhighlight>
 +
-Berna3.14

Revision as of 12:34, 1 April 2014

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


//Processo con prioritá 0 = Processo con piú alta prioritá
//Processo con prioritá 9 = Processo con meno prioritá
monitor priocoop {
	condition oktogo[10];
	int wait[10] = 0,0,0,0,0,0,0,0,0;
	int running;
	priocoop.init(prio) {
		if(running != 0) {
			wait[prio]++;
			oktogo[prio].wait;
			wait[prio]--;
		}

		running++;
	}

	priocoop.yield(prio) {
		running--;
		for(int i = 0;i<10;i++) {
			if(wait[i] != 0) {
				oktogo[i].signal();
				wait[prio]++;
				oktogo[prio].wait;
				wait[prio]--;
				break();
			}
		}
		running++;
	}

	priocoop.fini() {
		running--;
		for(int i = 0;i<10;i++) {
			if(wait[i] != 0) {
				oktogo[i].signal();
				break();
			}
		}

	}
}

-Midolo


//0: priorita' maggiore
//9: priorita' minore
cond oktoenter[10];
int count[10];
bool running = false;

//restituisce la priorita' maggiore che ha un processo in attesa
getprio() {
      	for(i=0;i<10;i++) {
		 if(count[i]>0)
			 break;
	 }
	 return i;
}

priocoop() {
	init (prio) {
		if (running) {
			count[prio]++;
			oktoenter[prio].wait();
			count[prio]--;
		}
		running = true;
	}
	yield(prio) {
		i=getprio();
		if (i < 10) {
			// running = false; 
			oktoenter[i].signal();
			count(prio)++
			oktoenter[proc].wait();
	                // running = true;
        	        count[prio]--;
		}
	}
	fini(prio){
		i=getprio();
		running=false;
		if(i<10)
			oktoenter[i].signal;
	}
}

-Berna3.14