---
title: "Synchronization issues in RTOS"
subject: "Embedded System"
chapter: 6
key: "semester_6/embedded_system:rtos-synchronization-issues"
source: https://www.bctengineer.com/q/semester_6/embedded_system/rtos-synchronization-issues
site: BCT Engineering
---

# Synchronization issues in RTOS

Embedded System · Chapter 6: RTOS

- Asked in: 2078 Baisakh, 4 marks; 2064 Poush (old course) (asked 2 times)
- Video: [Task Synchronisation | Shared Data, Priority Inversion, Deadlock | Embedded System & RTOS](https://www.youtube.com/watch?v=jQTQOMn24RM) — Ekeeda
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/embedded_system/rtos-synchronization-issues
- Whole chapter: https://www.bctengineer.com/md/semester_6/embedded_system/chapter-6

## Question

Explain different synchronization issues (problems faced when tasks share the same variables and functions, and their solutions).

## 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.

## Answer

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
1. **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.
2. **Critical section problem:** the code that accesses a shared resource must run by only one task at a time; otherwise data becomes inconsistent.
3. **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.
4. **Deadlock:** tasks wait forever for resources held by each other.
5. **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).
6. **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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Two tasks both do counter = counter + 1 and one update is lost. What is this?
   A. Race condition
   B. Deadlock
   C. Priority inversion
   D. Starvation
   Answer: A. The result depends on timing of read-modify-write. (Key point: Race condition)

2. What is priority inversion?
   A. A low-priority task runs first by design
   B. A task never gets the resource
   C. Tasks wait for each other forever
   D. A high-priority task is blocked by a low-priority task holding a lock while a medium-priority task runs
   Answer: D. The Mars Pathfinder problem; solved by priority inheritance or ceiling. (Key point: Priority inversion)

3. How to make a shared function reentrant?
   A. Use more global variables
   B. Use local variables and parameters, not globals
   C. Disable the RTOS
   D. Use static data
   Answer: B. Global or static data gives wrong results if pre-empted. (Key point: Non-reentrant functions)

4. How are critical sections protected?
   A. By message loss
   B. By raising all priorities
   C. Mutex/binary semaphore or briefly disabling interrupts
   D. By increasing the tick rate
   Answer: C. Only one task runs the critical section at a time. (Key point: Critical section protection)

## Related in Embedded System

- [Mutual exclusion via sleep and wake](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Amutual-exclusion-sleep-wake) — Embedded System, chapter 6

## Related in other subjects

- [FORTRAN constants, variables, library functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-constants-variables-library) — Computer Programming, chapter 11
- [Geotechnical problems and their solutions](https://www.bctengineer.com/question.md?key=semester_4%2Fsoil_mechanics%3Ageotechnical-problems-solutions) — Soil Mechanics, chapter 1, asked 2×
- [Clock sync problems; Chandy-Lamport](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aphysical-clock-problems-chandy-lamport) — Distributed System, chapter 5
- [Parent-child transactions; locking problems](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aparent-child-locking) — Distributed System, chapter 8
