RealTime Embedded Systems Ch 18 Resource Sharing Objectives

Real-Time Embedded Systems Ch. 18: Resource Sharing

Objectives Shared Variables Shared memory objects Semaphore Mutex Condition variables X. Fan: Real-Time Embedded Systems 2

Shared Variables Issues in using shared variables ◦ Data integrity ◦ Data loss ◦ Data duplication X. Fan: Real-Time Embedded Systems 3

Shared Memory X. Fan: Real-Time Embedded Systems 4

Data protection What is a critical section? What can go wrong with shared access? ◦ Data integrity violation ◦ Data loss ◦ Data duplication How do we protect it? ◦ Disable interrupts ◦ Use a semaphore X. Fan: Real-Time Embedded Systems 5

Semaphore Properties ◦ Object managed by the OS ◦ Has a counter Available if count > 0 Not available if count <= 0 Max_count ◦ Task wait list ◦ Access (decrement and increments the counter) Pend/post, Acquire/Release Procure/vacate Wait/Post (POSIX) X. Fan: Real-Time Embedded Systems 6

Semaphore X. Fan: Real-Time Embedded Systems 7

Semaphore State transitions X. Fan: Real-Time Embedded Systems 8

Using semaphore for task synchronization X. Fan: Real-Time Embedded Systems 9

Rendezvous Synchronization Pattern X. Fan: Real-Time Embedded Systems 10

Using semaphore for flow control X. Fan: Real-Time Embedded Systems 11

Using semaphore for resource protection X. Fan: Real-Time Embedded Systems 12

Define an order on semaphores to prevent circular wait X. Fan: Real-Time Embedded Systems 13

POSIX functions X. Fan: Real-Time Embedded Systems 14

Example X. Fan: Real-Time Embedded Systems 15

Limitation of semaphore: Recursive requests for a resource lock X. Fan: Real-Time Embedded Systems 16

Mutex Properties ◦ Object managed by the OS ◦ Unnamed binary semaphore Available if count : = 1 Not available if count : = 0 ◦ Thread Ownership ◦ Unlocked only by its owner thread ◦ Can be locked recursively ◦ Can use protocols for access management PIP, PCP, etc. X. Fan: Real-Time Embedded Systems 17

Using Mutex for memory management X. Fan: Real-Time Embedded Systems 18

Using Mutex for memory management: with waiting X. Fan: Real-Time Embedded Systems 19

POSIX functions X. Fan: Real-Time Embedded Systems 20

Example X. Fan: Real-Time Embedded Systems 21

Condition Variable X. Fan: Real-Time Embedded Systems 22

Using condition variable in Barrier synchronization X. Fan: Real-Time Embedded Systems 23

Using condition variable in Barrier synchronization X. Fan: Real-Time Embedded Systems 24

Using condition variable in Producer Consumer Pattern X. Fan: Real-Time Embedded Systems 25

Using condition variable in Producer Consumer Pattern X. Fan: Real-Time Embedded Systems 26

Using condition variables in Read-Write Locks X. Fan: Real-Time Embedded Systems 27
- Slides: 27