Download presentation
Presentation is loading. Please wait.
Published byJuliet Jenkins Modified over 6 years ago
1
Computer Science & Engineering Electrical Engineering
EE 472 – Embedded Systems Dr. Shwetak Patel Assistant Professor Computer Science & Engineering Electrical Engineering
2
Agenda Critical regions Semaphores Lab 3 questions Midterms results 2
Shwetak N. Patel - EE 472
3
Mars Pathfinder 1997
4
Multitasking Need to share resources Think about the data in Lab 2
5
Sharing Global variables Shared buffers Producer / Consumer model
6
Buffers Single buffer Multiple buffers
7
Intertask Communication
Messages Mailbox
8
Critical Sections Only one task can access a shared resource
A short segment of code that cannot be preempted
9
Critical Sections What are ways to address the concurrency problem?
10
Critical Sections Ways to address this
Don’t use a preemptive scheduler Mask interrupts Use protection code Flags Semaphores
11
Semaphores A type of flagging scheme Used to protect critical sections
Atomic operation Have two operations: Wait(s) or Pend(s) or P(s) Signal(s) or Post(s) or V(s)
12
Semaphores Also used for synchronization
13
Semaphores Task can relinquish control until blocking is over
Task is put in a waiting queue
14
Semaphores – Pros/Cons
Easy to use and implement One semaphore per resource (reduce blocking) Drawback: Can cause priority inversion
15
Priority Inversion Hard to debug and detect Prevention techniques
Priority inheritance
16
Deadlock Two or more processes wait indefinitely
17
Deadlock Prevention Conditions for deadlock (all 4 have to hold)
Mutual exclusion No preemption Hold and wait Circular wait
18
Class Exercise Task1 1 X Task2 2 Task3 3 Task4 4 Task5 5 Task6 6 X
Priority Resources R R R3 Task1 1 X Task2 2 Task3 3 Task4 4 Task5 5 Task6 6 X
19
Class Exercise How many semaphore are needed?
2 Where do you see priority inversion problems? Tasks 1,2,3 (R2)
20
Class Exercise Task1 1 X Task2 2 Task3 3 Task4 4 Task5 5 Task6 6 X
Priority Resources R R R3 Task1 1 X Task2 2 Task3 3 Task4 4 Task5 5 Task6 6 X
21
Class Exercise How many semaphore are needed?
3 Where do you see priority inversion problems? Tasks 1,2,3 (R1) and 1,2,3 (R2) and 1,2,4 (R1) Do you see any other problems? Potential deadlock between Tasks 1 and 3
22
Class Exercise Task 1 1. Initialize digital I/O port for input
2. Read digital input 3. Count rising edges on each input Task 2 1. Read Data from serial port 1 2. Check for errors in serial data 3. if data buffer is empty {write data payload to buffer} Task 3 1. Initialize digital I/O port to output 2. write data to digital outputs 3. toggle bit 0 of digital I/O port on and off (i.e. make a brief pulse on bit 0). Task 4 1. if data buffer is full {take data from buffer} 2. Write data to serial port 2 Task 5 1. Count number of bytes in data buffer 2. display byte count on LCD
23
Class Exercise What resources are being shared?
Do you see critical sections? Which tasks? Where in each task?
24
Class Exercise What resources are being shared?
IO and the buffer Do you see a critical sections? Yes Which tasks and what resources? 1 - io,2 - buffer,3 - io, 4 – buffer, 5 - buffer Where in each task?
25
Questions? Shwetak N. Patel - EE 472
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.