Operating System: Question Set – 33

Operating System: Question Set – 33

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?

FeatureCondition VariablesSemaphores
PurposeWaiting for conditionsCounting or mutual exclusion
State RetentionDo not retain state if no waitersRetain state (can count signals)
UsageUsed with a lockStandalone 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?

  1. Soft Real-Time Systems:
    • Allow occasional deadline misses.
    • Examples: Multimedia streaming.
  2. 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?

AspectShared MemoryMessage Passing
CommunicationDirectly through shared spaceExchange messages via the OS
PerformanceFaster but requires synchronizationSlower due to message overhead
ComplexityNeeds careful synchronizationEasier to implement

What are the differences between condition variables and semaphores?

AspectCondition VariablesSemaphores
PurposeWait for specific conditionsCounting or mutual exclusion
State PersistenceDo not retain state if no waitersRetain state (count persists)
LockingUsed with a lockStandalone synchronization tool

What is the difference between concurrency and parallelism?

AspectConcurrencyParallelism
DefinitionMultiple tasks in progressTasks running simultaneously
RequirementCan run on a single coreRequires multiple cores
FocusManaging access to shared resourcesIncreasing execution speed

How are deadlocks detected and resolved?

  1. Detection:
    • Use a wait-for graph to identify cycles.
    • Use algorithms like the Banker’s algorithm for resource allocation states.
  2. Resolution:
    • Terminate one or more processes.
    • Preempt and reallocate resources.

Leave a Reply

Your email address will not be published. Required fields are marked *