Difference between revisions of "ProvaTeorica 2014.02.22"
Jump to navigation
Jump to search
(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...") |
|||
Line 38: | Line 38: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | Alessandro |
Revision as of 09:25, 21 May 2014
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;
}
}
Alessandro