Download presentation
1
Prof. R K Joshi IIT Bombay
An Introduction to CCS Prof. R K Joshi IIT Bombay
2
Communication: agents and media
Agents: sender and receiver Medium: responsible to take message from one agent to another 5 types of media Sr no Precondition to send Precondition to receive Postcondition on send Postcondition to receive comments 1: Ether None: can always send message in medium New msg is created, Someone who executes receive may receive the msg Msg deleted from medium, Given to receiving agent Msgs not ordered, assynchronous commu, unbounded medium 2. Bounded Ether Either must not be full Same as above Msgs not ordered, asynchronous comm, bounded medium 3. Buffer (infinite) Same as 1 Same as above+ Receive and sends are matched in order of send Ordered, asynchronous, unbounded medium 4.Bounded buffer Same as 2 Sane as above Same as 3 Ordered, asynchronous, bounded medium 5. Shared memory cell Receiver may always receive, If msg exists, old msg is overwritten, else new msg is created if medium has no msg, null/default msg is received, else msg is returned, Msg not deleted from medium Single cell shm, no question of order as there is only 1 cell, bounded medium-1 cell, asynchronous
3
Difference between agents and media
In above model, media is passive entity and agents are active As an alternative consider only agents and arrows between them: Media can be simulated by agents Since arrows are simple indivisible communication actions; communication behavior is attributed to the medium (not to arrows) and intermediate agents acting as media can implement postconditions on send and receive. Media may not be fully passive If you want to simulate one media in terms other by means of local variables e.g. bounded buffer in terms of ether, you have to anyway choose an active representation and since you can simulate media by agents, the simulation of one media in terms of another can be done. medium sender receiver
4
Converging to a simpler model:
Agents and connections Both the below models are possible Medium is implemented by S & R themselves e.g. blocking send R S S M R Medium is more complex: implemented by Agent M e.g. non-blocking buffered send
5
Agent Adjacency through connections between input and output ports
Ports: agents communicate through ports i.e. agent adjacency is defined along specific ports in agents. Ports are either input or output ports. (No bidirectional ports in the calculus-they can be simulated by a pair of ports) Agent adjacency is captured as arrows (arrows are not channels!) (1) arrows between agent to agent:: a in below example (2) Between environment and agent: incoming arrow at p1 in below example (3) Within an agent among subagents: b in below example There is no limit to no. of agents that can be connected to a particular port p6 p1 a11 p2 p2 a12 p6 A2 p7 A1 has sub agents a11, a12, a13 A2 is another agent p1, p2, p3, p4, p5, p6, p7 are input ports __ __ __ __ __ __ __ p1, p2, p3, p4, p5, p6, p7 are output ports p4 p5 p3 p3 p4 a13 p5
6
Agent Expressions (or agent definitions)
- p1 is an input port - p2 with a bar indicates that it is an output port C =def p1 (x).C’(x) C’ (y) =def p2 (y).C Explanation: in agent C, receive a value from port p1 into x and then continue to execute code for agent C’. Pass x as parameter to C’ In agent C’, send the incoming parameter into output port p2, and continue to execute code of agent C In these agent equations, C and C’ are agent names Their agent expressions are given on right hand side. Prefixes p1(x) and p2(y) in agent expressions are handshakes Alternative expression for C: C =def p1(x). p2(x). C
7
Input and Output are indivisible
The connector only defines adjacency and not a channel. Hence: An input and a corresponding output action is indivisible In the sense there is no intermediate channel to hold an output value.
8
Variable scoping rules
Variables in prefix: scope in over the agent expression E.g. p1(x).p2(x).C Variables as formal parameters in agent names (like arguments to object constructors in OOPLs) scope is over the whole equation E.g. C’(y) = p2(y).C
9
Another Example Prefix Combinator (underscores are used instead of bars on top for output ports)
C =def p1(x).p2(y).p3.(x).p4(y).C This can be rewritten with only 1 prefix per agent expression as below: C =def p1(x).C’(x) C’(a) =def p2(y).C’’(a,y) C’’(b,c) =def p3(b).C’’’(c) C’’’(d) =def p4(d).C Dot ‘.’ is a combinator called prefix combinator Prefix combinator is used to implement a sequence of agent expressions Combinators are operators that build bigger agent expressions by means of combinations of smaller agent expressions
10
Parameters in input and output actions
Parameters in input actions are variables Parameters in output actions can be expressions For example: Twice =def in(x).out(2*x).Twice Sum =def in1(x).in2(y).out(x+y).Sum
11
Summation Combinator C =def D + E in oleft oright in c1 c2 c1 c2 c3
C can behave either as agent expression D or as expression E. The choice is non-deterministic Example: C1 =def in(x).out(x).C1 + env(x).out(x).C1 C2 =def ileft(x).oright(x).C2 + iright(x).oleft(x).C2 C3 =def in(x).out(x).C3 + env(x).out(x).C3 (You could have also written C3 =def C1 because its behavior is same as that of C1… but connections matter!) – is deadlock possible in the below system? in oleft oright in c1 c2 c1 c2 c3 env out ileft iright out env Exercise1: solve the same problem without an intermediate agent Notice: without connections, the above agent expressions do not give complete description of the full system of collaborating agents. We will later define Combinator, which will express the connections that the diagram above expresses.
12
Answer to exercise 1 C1 =def env(x).out(x).C1 + in(x).out(x).C1
C2 =def C1 Exercise2): what’s the difference between the above and C1=def env(x).in(x).out(x).C1 C2=def C1 c1 c2 env out in
13
Another Example of Summation Combinator
V =def 2r.big.collect.V + 1r.little.collect.V V is a vending machine. One can insert 1 rupee, and specify choice as little chocolate and then collect the chocolate. Another possible sequence is to insert a 2 rupee coin, specify choice as big chocolate and then collect it. Note that collect is an input action from environment and unless collection happens, the machine will not accept another input. big little 1r 2r collect
14
Yet Another Example: Semaphore
S is a semaphore agent. Assume that semaphore is initialized to available. S =def V.S + P.V.S P S V
15
More Exercises 3. Write an expression and diagram for the following system: An agent randomly picks integers either from keyboard or from over network and prints them onto a printer. It’s an infinite process. printer is an agent. 4. Write a scheduler which picks up tasks from 2X2 input streams as follows: 2 streams are reserved for high priority incoming tasks 2 streams are reserved for lower priority incoming tasks Scheduler must pick up 2 tasks non-deterministically from any of the two hp streams. Then it must pick up 1 task non-deterministically from any of the 2 lp streams. After this the scheduler repeats this process again. Whenever the scheduler picks up a task, it sends it to processor agent 5. Upgrade the above scheduler such that if there in no input on a specific stream, it should continue with another if input is available on that stream. E.g. if hp lines are empty for sometime, the scheduler should continue with lp lines, till something becomes available on hp lines, from where, it again continues previous behavior. (Assume that hp tasks always come in pairs, one hp task on each hp line)
16
Answer to Exercise 3 C =def (kbd(x) + nw(x)).out(x).C
prn =def in(x).prn C in prn kbd out nw
17
Answer to Exercise 4 sch processor out hp1 in lp2 hp2 lp1
sch = (( (hp1(x)+hp2(x)).(hp1(y)+hp2(y)).out(x).out(y) ). ( (ip1(x) + ip2(x)).out(x)) ).sch processor =def in(x).processor sch processor out hp1 in lp2 hp2 lp1
18
Composition Combinator
C1 | C2 means C1 and C2 are composed together through port connections. Examples of composition have already been seen in past few slides; however, till now, we have been representing compositions through diagrams. If we use the above combinator in our specification, diagrams will not be needed to show composition. Following rule will be used for forming connections: In C1 | C2, all the complimentary ports (i.e. input and output ports with same label) will be connected. This gives us a flow graph. Exercise 6): Using the composition combinator, reworkout answer to exercise 3. Exercise 7) do the same for answer to ex. 1. Solve the deadlock problem in example on p. 11
19
Answer to Exercise 6 C =def (kbd(x) + nw(x)).p(x).C prn =def p(x).prn
diagram is not necessary. It can be generated from above specification.
20
Answer to Exercise 7 C1 =def env(x).p(x).C1 + p(x).p(x).C1 C2 =def C1
21
Restriction Combinator
(C | D)\L After C is composed with D, all ports listed in set L are made internal. Subsequently these ports will not be available to external world. Restriction when applied during process of composition can also serve as a mechanism to restrict composition. For example: Given C1:{p,q,p,q} C:L specifies that agent C (C1 in our case), in its actions, will use ports of which names form proper subset of set of labels L. This set is called sort. In our case, the sort is specified to be p,q,p,q Given C2:{p,q,p,q} Composition C1\{p} | C2\{p} hides p and its complement in C1 and p and its complement in C2 before they are composed Composition C1\{p,p}|C2\{q,q} results in no connections between C1 and C2. Given NULL:{ } Given C:{p,q,p,q} composition (NULL|C1)\L{p,p} is equivalent to expression C\{p} Hiding internally unconnected output ports from further compositions with external world makes them work like sinks. In C\L, both complements of all labels in set L are internalized and made unavailable for further composition Restriction reduces the sort of composed agent.
22
Relabeling Combinator
C [ f ] All labels in agent expression for agent C get replaced as dictated by relabeling function f. f = {l1’/l1, l2’/l2, …… ln’/ln} i.e. Replace l1 by l1’ and l1 by l1’, replacel2 by l2’ and l2 by l2’ and so on. i.e. f(l1)=l1’, f(l1)=l1’ and so on Note that relabeling function respects complements. Both the complements are relabeled.
23
Example: Semaphore used by re-labeling as a resource (e.g. printer)
S =def V.S + P.V.S Printer =def S [startwrite/P, endwrite/V] S P V
24
Using Sequences as agent parameters
C <v1, v2, …. Vn>
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.