Task Cooperation via Data Transfer Only u Definition

  • Slides: 16
Download presentation
Task Co-operation via Data Transfer Only u Definition (adapted to concurrency): “A means by

Task Co-operation via Data Transfer Only u Definition (adapted to concurrency): “A means by which to exchange and share data” u Type of data transfer: u Selective (specifies the order in which data is accessed) Uses the notions of “pool” and “channel”. u u Non-selective (does not specify the order or time at which data is accessed) Ernest Cachia University of Malta “Designing Concurrency” Slide No. 1 of part 3

Non-Selective Data Transfer - The Pool u Used for movement of data between tasks

Non-Selective Data Transfer - The Pool u Used for movement of data between tasks u Is a basic storage entity u Considered a common resource u Controlled by mutual exclusion mechanisms (semaphores are usually adopted as the control mechanisms) u Non-destructive read and destructive write u Easy to implement (usually as machine RAM) u Require strict control to avoid unwanted data overwriting Ernest Cachia University of Malta “Designing Concurrency” Slide No. 2 of part 3

Pool Example Task 1 Determine status Pool symbol Task 3 s Get current status

Pool Example Task 1 Determine status Pool symbol Task 3 s Get current status statu s Task 1 status Task 2 Pool Ernest Cachia University of Malta “Designing Concurrency” Slide No. 3 of part 3 Compute new mode statu Task 2 Task 3 A more specific possibility A concrete example

Combining Pool Access and Semaphores status {Get current status} wait. For(sem 1); Read. Pool(current_status,

Combining Pool Access and Semaphores status {Get current status} wait. For(sem 1); Read. Pool(current_status, status); Signal(sem 1); Determine status Get current status sta tus {Determine status} Wait. For(sem 1); Write. Pool(current_status, status); Signal(sem 1); Excl. Write. Pool(current_status, sem 1 status); Excl. Read. Pool(current_status, status); current_status Ernest Cachia University of Malta “Designing Concurrency” Slide No. 4 of part 3

Selective Data Transfer - The Channel u Used for movement of data between tasks

Selective Data Transfer - The Channel u Used for movement of data between tasks u Exhibits limited and transient buffering functions u Can buffer more than one data element (to avoid data loss by overwriting when tasks proceed at different speeds) u FIFO operation u Destructive read non-destructive write u Usually implemented in machine RAM u Require some form of buffer control structure Ernest Cachia University of Malta “Designing Concurrency” Slide No. 5 of part 3

Channel Example Channel Task 1 Task 2 u Task 1 (producer) ch 1 Generate

Channel Example Channel Task 1 Task 2 u Task 1 (producer) ch 1 Generate coords Channel symbol Process coords Task 2 (consumer) Write to channel Read from channel What dictates the minimal size of a channel? … u Amount of data transferred (storage element size) u Production rate (speed at which buffer space is used up) u Consumption rate (speed at which buffer space is freed) u Exceptional conditions: Ernest Cachia University of Malta “Designing Concurrency” Slide No. 6 of part 3 u Writing when buffer is full u Reading when buffer is empty

Channel Construction Example (using “ch 1” in previous slide as example) u Main structure

Channel Construction Example (using “ch 1” in previous slide as example) u Main structure used to build channels is the circular buffer: Ernest Cachia University of Malta “Designing Concurrency” Slide No. 7 of part 3 0 1 2 3 4 5 6 7 8 9 CP 0 1 2 3 4 5 6 7 8 9 C P Ch 1 is initialised and contains no data 3 co-ordinates are produced and none are consumed 2 co-ordinates are consumed and none are produced

Some Code for Channel Implementation (1) (using “ch 1” in previous slide as example)

Some Code for Channel Implementation (1) (using “ch 1” in previous slide as example) {COMMON DATA STRUCTURE DECLERATIONS} type Coord_range = [0. . 100]; {Hypothetical co-ordinate range} Coords = Array[0. . 1] of Coord_range; Buffer = Array[0. . 9] of Coords; Channel = record Data: Buffer; C_ptr, P_ptr: [0. . 9]; end; var ch 1: Channel; {WRITE TO CHANNEL} {READ FROM CHANNEL} if P_ptr=((C_ptr+1) MOD 10) then if C_ptr=P_ptr then Suspend. Producer Suspend. Consumer else ch 1. Data[P_ptr]: ={data}; {data}: =ch 1. Data[P_ptr] P_ptr: =(P_ptr+1) MOD 10; C_ptr: =(C_ptr+1) MOD 10; end; Ernest Cachia University of Malta “Designing Concurrency” Slide No. 8 of part 3

Code Encapsulation (using “ch 1” in previous slide as example) {WRITE TO CHANNEL} {Some

Code Encapsulation (using “ch 1” in previous slide as example) {WRITE TO CHANNEL} {Some code} Wait. For(Not. Full); Wait. For(Channel. Free); Write. To. Channel; Signal(Channel. Free); Signal(Not. Empty); {Some more code} {READ FROM CHANNEL} {Some code} Wait. For(Not. Empty); Wait. For(Channel. Free); Read. From. Channel; Signal(Channel. Free); Signal(Not. Full); {Some more code} A Petri Net is used in the next slide to model channel behaviour (only a 3 data element buffer is assumed for the sake of example clarity). Ernest Cachia University of Malta “Designing Concurrency” Slide No. 9 of part 3

Petri Net Representing Channel Behaviour (using a 3 data element channel shared between one

Petri Net Representing Channel Behaviour (using a 3 data element channel shared between one producing and one consuming task) Ernest Cachia University of Malta “Designing Concurrency” Slide No. 10 of part 3 Buffer B 3 Consumer Producer write read B 2 consume C 1 C 2 write read B 1 write read B 0 produce P 2 P 1

Combined Synchronisation and Data Transfer u u Comprising event signalling and data movement The

Combined Synchronisation and Data Transfer u u Comprising event signalling and data movement The concept of a “mailbox” is used. This incorporates: u Data storage facilities u Event signals - “post”, “pend”, and “check” u u Widespread use of “mailbox” concept in modern operating systems Once a task “posts”, it is suspended pending a “pend” signal. The inverse is also true (i. e. once a task “pends” it is suspended pending a “post” A task can observe the status of the mailbox via “check” All data in mailbox is transferred at rendezvous time Ernest Cachia University of Malta “Designing Concurrency” Slide No. 11 of part 3

Mailbox Example Mailbox Task 1 Mailbox symbol Task 2 Task 1 (producer) Task 2

Mailbox Example Mailbox Task 1 Mailbox symbol Task 2 Task 1 (producer) Task 2 (consumer) mb 1 1 Generate profile 2 Process profile Post to mailbox Task 1 Task 2 Ernest Cachia University of Malta “Designing Concurrency” Slide No. 12 of part 3 A B C D E F GH time Pend on mailbox Timeline milestones A: 1 posts profile data & suspend B: 2 starts C: 2 pends on data, 1 re-activates D: 2 ends E: 2 re-starts F: 2 suspends pending post by 1 G: 1 posts & continues, 2 re-activ H: 2 ends (2 nd time)

Mailbox Code Encapsulation (using “mb 1” in previous slide as example) {WRITE TO MAILBOX}

Mailbox Code Encapsulation (using “mb 1” in previous slide as example) {WRITE TO MAILBOX} {Some code} Wait. For(Mailbox. Free); Post. To(mb 1); Signal(Mailbox. Free); {Some more code} Ernest Cachia University of Malta “Designing Concurrency” Slide No. 13 of part 3 {GET FROM MAILBOX} {Some code} Wait. For(Mailbox. Free); Pend. On(mb 1); Signal(Mailbox. Free); {Some more code}

The Task Diagram (TD) u Shows concurrent system functionality in terms of independent tasks

The Task Diagram (TD) u Shows concurrent system functionality in terms of independent tasks u Shows task interaction with entities external to the system being developed u Shows the nature of co-operation between system tasks using the previously discussed methods (see preceding slides) u Provides a simple, clear and intuitive means to represent concurrent behaviour at a high (initial) level Ernest Cachia University of Malta “Designing Concurrency” Slide No. 14 of part 3

Notation used in TDs <pool_ID> Pool Task signal Channel Event flag <channel_ID> <ID> Mailbox

Notation used in TDs <pool_ID> Pool Task signal Channel Event flag <channel_ID> <ID> Mailbox <mailbox_ID> Ernest Cachia University of Malta “Designing Concurrency” Slide No. 15 of part 3 Independent task Task co-operation <ID> External entity

TD Example (Adapted from “Real-Time Software Systems” by J. E. Cooling) Display Task Vehicle

TD Example (Adapted from “Real-Time Software Systems” by J. E. Cooling) Display Task Vehicle Sensors Data Acquisit. Task Local Display Unit Control Function Task Actuator Control Task Serial Comms OP Task Serial Comms Link Serial Comms IP Task Ernest Cachia University of Malta “Designing Concurrency” Slide No. 16 of part 3 Vehicle Actuators