Operating System: Question Set – 33
Operating System: Question Set – 33
by
codecrucks
·
Published
· Updated
How does the OS handle concurrency in multi-core systems?
- Thread Affinity: Binds threads to specific cores.
- Load Balancing: Distributes threads evenly across cores.
- Lock-free Algorithms: Reduce contention on shared resources.
- Cache Coherence Protocols: Ensure consistency of shared data across cores.
What is hardware support for concurrency?
- Test-and-Set Instructions: Atomic operation to test and modify a lock.
- Compare-and-Swap (CAS): Atomic instruction to update a value only if it matches an expected value.
- Memory Barriers: Ensure proper ordering of memory operations in multi-threaded environments.
What are non-blocking synchronization techniques?
- Lock-Free: At least one thread makes progress without being blocked.
- Wait-Free: All threads make progress within a bounded time.
- Obstruction-Free: Progress is guaranteed in the absence of contention.
How do condition variables differ from semaphores?
| Feature | Condition Variables | Semaphores |
| Purpose | Waiting for conditions | Counting or mutual exclusion |
| State Retention | Do not retain state if no waiters | Retain state (can count signals) |
| Usage | Used with a lock | Standalone synchronization tool |
What is the Peterson’s Algorithm?
Peterson’s algorithm is a classic solution for achieving mutual exclusion in concurrent programming.
- It uses two shared variables: a flag for each process and a turn variable to decide which process enters the critical section.
- It satisfies mutual exclusion, progress, and bounded waiting conditions.
How does the operating system implement context switching in concurrency?
Context switching involves saving the state of a currently running process and restoring the state of another process.
- Steps: Save CPU registers → Save process state → Load new process state → Restore registers.
- The kernel handles this efficiently to maintain concurrency.
What are lock-free and wait-free algorithms?
- Lock-Free Algorithms:
- Ensure that at least one thread makes progress in a finite number of steps.
- Example: Compare-and-Swap (CAS) operations.
- Wait-Free Algorithms:
- Ensure all threads make progress in a bounded number of steps.
- Useful for real-time systems.
What are soft and hard real-time systems in concurrency?
- Soft Real-Time Systems:
- Allow occasional deadline misses.
- Examples: Multimedia streaming.
- Hard Real-Time Systems:
- Must meet all deadlines strictly.
- Examples: Airbag systems in cars.
What is the difference between shared memory and message passing in concurrency?
| Aspect | Shared Memory | Message Passing |
| Communication | Directly through shared space | Exchange messages via the OS |
| Performance | Faster but requires synchronization | Slower due to message overhead |
| Complexity | Needs careful synchronization | Easier to implement |
What are the differences between condition variables and semaphores?
| Aspect | Condition Variables | Semaphores |
| Purpose | Wait for specific conditions | Counting or mutual exclusion |
| State Persistence | Do not retain state if no waiters | Retain state (count persists) |
| Locking | Used with a lock | Standalone synchronization tool |
What is the difference between concurrency and parallelism?
| Aspect | Concurrency | Parallelism |
| Definition | Multiple tasks in progress | Tasks running simultaneously |
| Requirement | Can run on a single core | Requires multiple cores |
| Focus | Managing access to shared resources | Increasing execution speed |
How are deadlocks detected and resolved?
- Detection:
- Use a wait-for graph to identify cycles.
- Use algorithms like the Banker’s algorithm for resource allocation states.
- Resolution:
- Terminate one or more processes.
- Preempt and reallocate resources.