90 likes | 166 Views
CIS 725. Homework 1. Problem 1. S:: ns = 1; na = 1 do ns < na + W / avail( nl_buff ) / sbuff [ns] = null sbuff [n] = nl_buff ; R!( sbuff [ns],ns); R! ( sbuff [ns], ns) ns++ [] R ? ack (s) if s > na then na = s od. Problem 1. R:: nr = 1 do
E N D
CIS 725 Homework 1
Problem 1 S:: ns = 1; na = 1 do ns < na + W /\ avail(nl_buff) /\ sbuff[ns] = null sbuff[n] = nl_buff; R!(sbuff[ns],ns); R! (sbuff[ns], ns) ns++ [] R ? ack(s) if s > na then na = s od
Problem 1 • R:: nr = 1 do S ? (D,x) if nr = x then deliver(D); nr++ S ! Ack(nr); S!Ack(nr) od
Problem 2 S:: ns = 1; na = 1 do not sent /\ avail(nl_buff) sbuff = nl_buff; R!(sbuff); sent = true; start timer [] R ? ack(s) sent = false [] timeout -> R!sbuff; start timer od
Problem 2 • R:: do S ? d deliver(D); S ! Ack od
Problem 3 A: state = idle; req_recd = false do [] state == idle state = read_request; C ! r_request [] C ? grant state = reading [] state == reading state = idle [] state == idle && req_recd C ! Grant; req_recd = false [] C ? w_request -> req_recd = true od B: (identical to A) C: state = idle; req_recd = false do [] state == idle state = write_request; A ! w_request; B ! w_request; [] A ? grant granta = true [] B ? grant grantb = true [] granta && grantb state = writing; granta = false; grantb = false [] state ==writing state = idle [] state == idle && req_recdA A ! grant; req_recdA = false [] state == idle && req_recdB B ! grant; req_recdB = false [] A ? r_request -> req_recdA = true [] B ? r_request -> req_recdB = true od
Problem 4 Token-based system • P1: hold = false; in_cs = false; sbit = 0; rbit = 0 do ? Token,b !ack,b; if (b == rbit) then hold = true; rbit = !rbit [] hold /\ not in_cs ! token,sbit; hold =false; start timer [] timeout !token,sbit [] ? ack,b if (b == sbit) cancel timer; sbit = !sbit [] hold in_cs = true [] in_cs in_cs = false od
Problem 5 S:: ns = 1; na = 1 do ns < na + W /\ R!(sbuff[ns],ns); ns++; cancel timer; if ns = na + W then start timer [] ack[na] na++ [] R ? ack(x,y) while x <= y do ack[x] = true; x++ od [] timeout R! (sdata[na],na) od
R:: nr = 1; sa = 1 do S ? (x,y) if y >= sa then rdata[y] = x; recd[y] = true else s!ack(y, nr-1) [] recd[nr] nr = nr + 1 [] sa < nr S!ack(sa, nr - 1); sa = nr od