- Asked 2/19
- 2078 Baisakh · 4 marks
- 2064 Poush (old course)
Synchronization issues in RTOS
Short answer
Concurrent access to shared data causes race conditions, critical section violations, and non-reentrant problems. Solutions include mutexes/semaphores, reentrant functions, priority inheritance for priority inversion, and resource ordering to prevent deadlock.
Explain different synchronization issues (problems faced when tasks share the same variables and functions, and their solutions).
In an RTOS, several tasks run concurrently and often share global variables, buffers, functions and I/O devices. If access is not coordinated, the result depends on the order of execution, which causes the following issues.
Issues
- Race condition: two tasks read-modify-write a shared variable at the same time; the result depends on timing. Example: both tasks do counter = counter + 1 and one update is lost.
- Critical section problem: the code that accesses a shared resource must run by only one task at a time; otherwise data becomes inconsistent.
- Non-reentrant functions: a shared function that uses global or static data gives wrong results if a task is pre-empted inside it and another task calls it.
- Deadlock: tasks wait forever for resources held by each other.
- Priority inversion: a high-priority task is blocked by a low-priority task holding a lock, while a medium-priority task runs (Mars Pathfinder problem).
- Starvation: a low-priority task never gets the resource.
Solutions
- Mutual exclusion: protect critical sections with mutex/binary semaphore, or disable interrupts for very short sections.
- Semaphores (counting) to control access to a pool of resources and for signalling.
- Make functions reentrant: use local variables and parameters, not globals.
- Priority inheritance / priority ceiling to avoid priority inversion.
- Resource ordering / request all at once to avoid deadlock.
- Message queues, mailboxes and events for safe communication instead of shared variables.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Mutual exclusion via sleep and wake · Embedded System, chapter 6
- FORTRAN constants, variables, library functions · Computer Programming, chapter 11
- Geotechnical problems and their solutions · Soil Mechanics, chapter 1 · asked 2×
- Clock sync problems; Chandy-Lamport · Distributed System, chapter 5
- Parent-child transactions; locking problems · Distributed System, chapter 8