<?xml version='1.0' encoding='utf-8'?><!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.0//EN' 'http://www.docs.uu.se/docs/rtmv/uppaal/xml/flat-1_0.dtd'><nta><declaration>int n = 0;

/* Two semafores: */
const int NUM_SEM = 2;
typedef int[0,NUM_SEM-1] sem_t;
/* Their names: */
const int s = 0;
const int delay = 1;

/* Two processes: */
const int NUM_PROC = 2;
typedef int[0,NUM_PROC-1] pid_t;

chan semWait[NUM_SEM][NUM_PROC], semSignal[NUM_SEM], block[NUM_PROC], unblock[NUM_PROC];</declaration><template><name x="5" y="5">Producer</name><parameter>const pid_t id</parameter><location id="id0" x="224" y="416"></location><location id="id1" x="224" y="288"></location><location id="id2" x="384" y="160"></location><location id="id3" x="224" y="160"></location><location id="id4" x="224" y="32"></location><init ref="id4"/><transition><source ref="id0"/><target ref="id4"/><label kind="synchronisation" x="-8" y="208">semSignal[s]!</label><nail x="224" y="448"/><nail x="96" y="448"/><nail x="96" y="32"/></transition><transition><source ref="id1"/><target ref="id0"/><label kind="guard" x="256" y="328">n==1</label><label kind="synchronisation" x="264" y="344">semSignal[delay]!</label><nail x="256" y="352"/></transition><transition><source ref="id1"/><target ref="id0"/><label kind="guard" x="160" y="328">n!=1</label><nail x="192" y="352"/></transition><transition><source ref="id3"/><target ref="id1"/><label kind="assignment" x="232" y="208">n++</label></transition><transition><source ref="id2"/><target ref="id3"/><label kind="synchronisation" x="288" y="176">unblock[id]?</label><nail x="304" y="176"/></transition><transition><source ref="id3"/><target ref="id2"/><label kind="synchronisation" x="280" y="120">block[id]?</label><nail x="304" y="144"/></transition><transition><source ref="id4"/><target ref="id3"/><label kind="synchronisation" x="232" y="80">semWait[s][id]!</label></transition></template><template><name>Consumer</name><parameter>const pid_t id</parameter><location id="id5" x="192" y="480"></location><location id="id6" x="352" y="224"></location><location id="id7" x="192" y="352"></location><location id="id8" x="192" y="224"></location><location id="id9" x="352" y="96"></location><location id="id10" x="192" y="96"></location><location id="id11" x="192" y="-32"></location><init ref="id11"/><transition><source ref="id5"/><target ref="id10"/><label kind="guard" x="-40" y="296">n!=0</label><nail x="0" y="512"/><nail x="0" y="64"/></transition><transition><source ref="id5"/><target ref="id10"/><label kind="guard" x="24" y="248">n==0</label><label kind="synchronisation" x="24" y="264">semWait[delay][id]!</label><nail x="64" y="480"/><nail x="64" y="96"/></transition><transition><source ref="id7"/><target ref="id5"/><label kind="synchronisation" x="200" y="408">semSignal[s]!</label></transition><transition><source ref="id6"/><target ref="id8"/><label kind="synchronisation" x="240" y="240">unblock[id]?</label><nail x="272" y="240"/></transition><transition><source ref="id8"/><target ref="id6"/><label kind="synchronisation" x="240" y="192">block[id]?</label><nail x="272" y="208"/></transition><transition><source ref="id8"/><target ref="id7"/><label kind="assignment" x="208" y="288">n--</label></transition><transition><source ref="id10"/><target ref="id8"/><label kind="synchronisation" x="96" y="152">semWait[s][id]!</label></transition><transition><source ref="id9"/><target ref="id10"/><label kind="synchronisation" x="240" y="112">unblock[id]?</label><nail x="272" y="112"/></transition><transition><source ref="id10"/><target ref="id9"/><label kind="synchronisation" x="240" y="56">block[id]?</label><nail x="272" y="80"/></transition><transition><source ref="id11"/><target ref="id10"/><label kind="synchronisation" x="72" y="16">semWait[delay][id]!</label></transition></template><template><name>Sem</name><parameter>const sem_t id, const int cnt</parameter><declaration>int count = cnt;

int proc_id = 0;

// The queue:
int next_free = 0;
pid_t queue[NUM_PROC];

void push (int pid)
{
  if (next_free&lt;NUM_PROC)
  {
    queue[next_free] = pid;
    next_free++;
  }
}

void pop ()
{
  if (next_free&gt;0)
  {
    queue[next_free-1] = 0;
    next_free--;
  }
}</declaration><location id="id12" x="0" y="128"><committed/></location><location id="id13" x="384" y="128"><committed/></location><location id="id14" x="192" y="128"></location><init ref="id14"/><transition><source ref="id13"/><target ref="id14"/><label kind="guard" x="288" y="112">count&gt;=0</label><label kind="assignment" x="288" y="128">proc_id = 0</label></transition><transition><source ref="id12"/><target ref="id14"/><label kind="guard" x="56" y="112">count&gt;0</label></transition><transition><source ref="id12"/><target ref="id14"/><label kind="guard" x="32" y="184">count&lt;=0</label><label kind="synchronisation" x="32" y="200">unblock[queue[next_free-1]]!</label><label kind="assignment" x="32" y="216">pop()</label><nail x="0" y="192"/></transition><transition><source ref="id14"/><target ref="id12"/><label kind="synchronisation" x="32" y="32">semSignal[id]?</label><label kind="assignment" x="32" y="48">count++</label><nail x="0" y="64"/></transition><transition><source ref="id13"/><target ref="id14"/><label kind="guard" x="304" y="184">count&lt;0</label><label kind="synchronisation" x="264" y="200">block[proc_id]!</label><label kind="assignment" x="264" y="216">push(proc_id),
proc_id = 0</label><nail x="384" y="192"/></transition><transition><source ref="id14"/><target ref="id13"/><label kind="select" x="312" y="0">i:pid_t</label><label kind="synchronisation" x="264" y="16">semWait[id][i]?</label><label kind="assignment" x="288" y="32">count--,
proc_id = i</label><nail x="384" y="64"/></transition></template><instantiation>P = Producer(0);
C = Consumer(1);
s_sem = Sem(s,1);
delay_sem = Sem(delay,0);
</instantiation><system>system P,C,s_sem,delay_sem;</system></nta>
