1 / 11

Assignment 4 - FSP

Assignment 4 - FSP. A variable store values in the range 0..N and supports the actions read and write . Model the variable as a process, VARIABLE, using FSP. The process’s LTS graph for N=2 is shown below. Your FSP model must produce an identical graph. Assignment 4 - FSP. Solution.

mairi
Download Presentation

Assignment 4 - FSP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assignment 4 - FSP • A variable store values in the range 0..N and supports the actions read and write. Model the variable as a process, VARIABLE, using FSP. The process’s LTS graph for N=2 is shown below. Your FSP model must produce an identical graph.

  2. Assignment 4 - FSP • Solution. const N = ... range R = 0..N VARIABLE = VAR[0], VAR[i:R] = (read[i] -> VAR[i] |write[v:R] -> VAR[v] ).

  3. Assignment 4 - FSP 2. A drinks dispensing machine charges 15p for a can of Sugarola. The machine accepts coins with denominations 5p, 10p and 20p and gives change. Using the alphabet {can, in.coin[10], in.coin[20], in.coin[5], out.coin[10], out.coin[5] } model the machine as an FSP process, DRINKS. A sample trace is shown below.

  4. Assignment 4 - FSP 2. Solution. DRINKS = CREDIT[0], CREDIT[0] = (in.coin[5] -> CREDIT[5] |in.coin[10] -> CREDIT[10] |in.coin[20] -> CHANGE[5]), CREDIT[5] = (in.coin[5] -> CREDIT[10] |in.coin[10] -> CHANGE[0] |in.coin[20] -> CHANGE[10]), CREDIT[10] = (in.coin[5] -> CHANGE[0] |in.coin[10] -> CHANGE[5] |in.coin[20] -> CHANGE[15]), CHANGE[0] = (can -> DRINKS), CHANGE[5] = (can -> out.coin[5] -> DRINKS), CHANGE[10] = (can -> out.coin[10] -> DRINKS), CHANGE[15] = (can -> out.coin[5] -> out.coin[10] -> DRINKS).

  5. Assignment 4 - FSP 3. Consider the following scenario. There are n bees and a hungry bear. They share a pot of honey. The pot is initially empty; its capacity is H portions of honey. The bear waits until the pot is full, eats all the honey and waits until the pot is full again: this pattern repeats forever. Each bee repeatedly gathers one portion of honey and puts it into the pot; if the pot is full when a bee arrives it must wait until the bear has eaten the honey before adding its portion: this pattern repeats forever. Model this scenario using FSP. The LTS graph for 4 bees is shown below. Your FSP model must produce an identical graph.

  6. Assignment 4 - FSP 3. continued.

  7. Assignment 4 - FSP 3. Solution. const H=4 const N=3 BEE = (addhoney -> BEE). BEAR = (eat -> BEAR). POT = POT[0], POT[i:0..H] = (when (i<H) [j:0..N].addhoney -> POT[i+1] |when (i==H) eat -> POT[0]). ||HONEYBEAR = ([i:0..N]:BEE || BEAR || POT).

  8. Assignment 4 - FSP 3. A, S and J work in a bar. A washes the dirty glasses one at a time and places each on a workspace. The workspace can hold a maximum of 10 glasses. S and J remove the glasses from the workspace one at a time and dry them. [You can ignore what happens to a glass after it is dried.] Unfortunately, there is only one drying cloth so S and J have to take turns at using it. However, as J is able to dry faster he dries two glasses at each turn while S only dries one. S takes the first turn at drying. Model the concurrent activity in the bar by completing the following FSP template.

  9. Assignment 4 - FSP 3. continued. S = (sdry -> S). J = (jdry -> jdry -> J). A = (wash -> A). // gw is the number of glasses washed. // j is the number of glasses washed by J in this turn. // turn indicates whose turn it is to wash. WORKSPACE(N=5) = WS[0][0][0], WS[gw:0..N][j:0..1][turn:0..1] = (..). ||BAR = (S || J || A || WORKSPACE(10)).

  10. Assignment 4 - FSP 3. continued.A sample trace is shown below.

  11. Assignment 4 - FSP 3. Solution. S = (sdry -> S). J = (jdry -> jdry -> J). A = (wash -> A). WORKSPACE(N=5) = WS[0][0][0], WS[gw:0..N][j:0..1][turn:0..1] = (gw[gw]-> WS[gw][j][turn] |when (gw<N) wash -> WS[gw+1][j][turn] |when (gw>0 && turn==0) sdry -> WS[gw-1][0][1] |when (gw>0 && j==0 && turn==1) jdry -> WS[gw-1][1][turn] |when (gw>0 && j==1 && turn==1) jdry -> WS[gw-1][0][0]). ||BAR = (S || J || A || WORKSPACE(20)).

More Related