ProvaTeorica 2014.02.22

From Sistemi Operativi
Revision as of 09:12, 21 May 2014 by Coci (talk | contribs) (Created page with "Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2014.02.21.tot.pdf] Esercizio c.1 <syntaxhighlight lang="C"> monitor bbwl { condition oktowrite; condition oktolog; condi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Testo: [1]

Esercizio c.1

monitor bbwl {
	condition oktowrite;
	condition oktolog;
	condition oktoread;
	int logging = 0;
	queue q;
	
	procedure entry write (eltype elem) {
	if (q.length() == MAXELEM || logging)
			oktowrite.wait();
	q.enqueue (elem);
	logging = 1;
	oktolog.signal();
	}
	
	procedure entry eltype log() {
	if (q.length == 0)
		oktolog.wait();
	eltype tmp = q.top();
	logging = 0;
	oktoread.signal();
	return tmp;
	}

	procedure entry eltype read() {
	if (q.length == 0 || logging)
		oktoread.wait();
	eltype tmp = q.dequeue();
	oktowrite.signal();
	return tmp;
	}
}