Week 7 - Concurrency Flashcards

1
Q

What does the view of an OS imply?

A

It implies that

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the differences between historic computer and computer this year?

A

Historical, computer were seen expensive, due to maximise utilisation

Now: Users expect concurrent execution of multiple tasks
Stream musics, edit file, update software etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What challenges arise when processes do not work independently in a system?

A

Competition for resources - processes may compete for access to shared resources like devices, files, or data, whether local or remote.

Cooperation: Processes can cooperate using mechanisms such as messages, shared memory or files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why do distributed applications face unique challenges?

A
  1. They support millions of users simultaneously, who may be reading or updating information.
  2. Examples,e include special networking sites (SNS), bank accounts, and online shopping platforms
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is it important to interleave multiple independent task in applications?

A
  1. Avoid freezing - Apps with GUIs should remain responsive during time-consuming tasks.
  2. Improve user experience - For system like banking databases,users should not wait in long queues for transactions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the key considerations for programmers and resources efficiency when building applications?

A
  • Programmer Efficiency: Developers should not need to create an OS for every app they build
  • Resource Efficiency: Applications should maximise the use of computing resources to ensure optimal performance.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can we managed concurrency and ensure correctness?

A
  1. Concurrency Management:
    Ensure multiple tasks can progress simultaneously.
    Avoid conflicts when accessing shared resources.
  2. Correctness:
    Prevent issues like race conditions, deadlocks, and starvation.
    Maintain program logic and data integrity.
  3. Key Questions:
    How can we do this conveniently?
    How can we do this efficiently?
    How can we maintain responsiveness?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can we provide programming mechanisms to allow concurrency?

A
  1. Threads: Lightweight processes enabling parallel execution within a program
  2. Programming Mechanisms:
    - Thread management libraries (e.g Java’s, Thread class
    - Synchronisation tools (e.g. mutexes, semaphores)
    - High-level abstraction (e.g thread pools,asynchrony/await)
  3. Goals: Efficient task execution and it is to improve responsiveness and resource utilisation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the primary concern of OS design regarding processes?

A

OS design focuses on:

  1. Management of Processes: Efficiently handling multiple processes to maximise CPU utilisation.
  2. Management of Threads: Enabling lightweight, concurrent execution within a process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the 3 main types of processing in OS design?

A
  1. Multi-programming (multitasking)
  2. Multiprocessing
  3. Distributed Processing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain the function(s) of the 3 main types of processing OS design

A
  1. Multiprogramming: Execute multiple tasks by sharing CPU time. Also, ensure efficient resources use and the system responsiveness
  2. Multiprocessing:
    - Involves multiple processors working in parallel
    - Enhances performance and fault torelance
  3. Distributed processing:
    - Distribute tasks across different systems
    - Enables scalability, fault tolerance, and resource sharing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 3 different contexts in concurrency?

A
  1. Multiple applications: this was invented to allow processing time to be shared among active applications
  2. Structured applications: extension of modular design and structured programming
  3. Operating system structure: OS themselves implemented as a set of processes or threads.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define some of the concurrency key terms

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the 2 main principles of concurrency?

A
  1. Interleaving and Overlapping
  2. Uni processor -
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What were the difficulties of concurrency?

A
  1. Sharing of global resources
  2. Difficult for the OS to manage the allocation of resources optimally
  3. Coordination of ‘ parallel’ and asynchronous ‘ processes’
    • Ensuring correct behaviour
    • Debugging of programming errors: behaviour can be non-deterministic, making it hard to identify and reproduce
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What design and management issues does concurrency raise for an operating system?

A

The OS concerns are such as:

  • Tracking processes: Keep track of all active and suspended processes
  • Resoruces allocation and de allocation: Manage resources such as CPU, I/O etc efficiently for each process.
  • Data and resource protection: Ensure processes cannot interfere with each other’s data or resources
  • Output independence: Ensure the process outcomes remain consistent, regardless of execution speed or order.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are responsibilities of the OS in managing concurrent processes?

A

The OS must:

  1. Process Management: Maintain control over process states and transitions
  2. Resource Management: Allocate CPU,memory, I/O efficiently
  3. Protection mechanisms: Adding isolation to prevent data corruption and resource misuse
  4. Consistency and independence: Ensure that process execution remains independent of variations in speed or scheduling
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Process interaction

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What causes conflict among concurrent processes, and what are some examples of resources they compete for?

A

There’s conflict when multiple processes compete for the same resource.

E.g: I/O devices: Printer, disk devices

Memory: Shaed or limited memory

Processor time: CPU cycles for excution

Clock: Timers and counters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the 3 key control problems faced in resource completion, and what do they ensure?

A
  1. Mutual exclusion: Ensures that only one process can access a critical section or resource at a time.
  2. Deadlocks: It happens when processes wait indefinitely for resources held by each other.
  3. Starvation: A process waits indefinitely due to resource allocation favouring others.
21
Q

Example of synchronisation process:

A
22
Q

What is a race condition?

A

A race condition occurs when:

  1. Multiple processes or threads read and write shared data terms concurrently.
  2. The final result depends on the order of execution of theses processes
23
Q

What are the key characteristics of the ‘Race condition’ in concurrent programming?

A
  • Processes “race” to complete their operations
  • The process that performs the last update determines the final value of the shared data
  • Can lead to unpredictable and incorrect results.
24
Q

What are the risk of a race condition?

A
  1. Unpredictable behaviour: Results may vary depending on the execution order
  2. Data inconsistency: Shared data may end up in an invalid state
  3. Program failures: Critical operations may produce incorrect outcomes, leading to bugs or crashes
25
Q

How to prevent the risk of race condition?

A

Use synchronisation mechanisms like locks,semaphores, or atomic operations to prevent race conditions

26
Q

Why do Race Conditions occur?

A
  1. Order execution:
  2. Scheduling:
  3. Outdated information:
27
Q

Critical section

A
28
Q

What are the two protocols in the critical section?

A
  1. Entry Protocol:
    • Process requests permission for entering a critical section: may have to wait/suspended until entry is granted
    • Process has to communicate that it entered critical section
  2. Exit Protocol: Process communicates to other processes that it has left the critical section
29
Q

What happens when the process is pre-emptied or interrupted in the critical sections?

A

The process can finish the execution of its critical section, even if it is pre-emptied or interruption.

30
Q

What problems can arise when enforcing mutual exclusion?

A

There are two major problems:

  1. Deadlocks:
    - Occurs when 2 or more processes wait indefinitely for resources held by each other.
    - None of the processes can proceed, resulting in a standstill.
  2. Starvation:
    - it happens when a process waits indefinitely to enter its critical section and if the the resource allocation consistently favours other processes
31
Q

What are the 3 requirements to solve the critical section problem?

A
  1. Serialisation of Access
  2. Bounded Waiting (No Starvation)
  3. Progress (likeness,No deadlocks)
32
Q

What is serialisation of access in the critical section problem?

A

Serialisation of access ensures:

  • Only one process can be enter the critical section at any given time
  • Prevents conflicts by avoiding simultaneous access to shared resources.
  • This ensures mutual exclusion maintain data consistency and system stability.
33
Q

What is bounded waiting in the critical section problem?

A

Bounded waiting ensures:

  1. Fairness: A process waiting to enter its critical section will be granted access within a defined waiting time period
  2. No starvation: So every process gets a turn to execute its critical section and prevent indefinitely delays
34
Q

What is progress (likeness, No deadlock) in critical section?

A

Progress ensures:

  • Non-interference: A process halted in its non-critical section does not block others from entering their critical section
  • Finite execution: The progress remains inside its critical section for a finite time only
  • Fair selection: Only processes actively waiting to enter their critical section participate in deciding which process enters next
35
Q

What are the 3 solutions to the critical section problem?

A
  1. Software solutions: Shared lock variables and busy waiting (polling/spinning/strict alternation)
  2. Hardware Solutions: Disabling interrupts and special H/W instructions (like compare&swap)
  3. Higher Level OS Constructs: Semaphores, Monitors, Message Passing
36
Q

What is a lock variable, and how is it used in concurrent programming?

A

A lock variable is shared data item used to protect critical sections. It is used to ensure only one process can enter the critical section at a time.

37
Q

What are the steps to use the lock variable?

A

Acquire the lock: Before entering the critical section.

Release the lock: After exiting the critical section

38
Q

What is a mutex?

A

A mutex (short for mutual exclusion) is a type of lock used to prevent multiple processes from accessing a critical section simultaneously.

It ensures mutual exclusion where only one process can hold the mutex at a time.

39
Q

How does Mutex relates to locks in critical section?

A

It acquired before critical section and released after. This is to prevent race conditions and ensures data integrity.

40
Q

Share lock

A
41
Q

What are the problems that shared lock have?

A
42
Q

What is busy waiting (aka polling or spinning) in concurrency?

A

Busy waiting occurs when a process continuously checks if a lock has become available, consuming CPU cycles without making progress.

Busy waiting presents shared memory, where the lock status is held in shared memory,allowing processes to check it repeatedly.

43
Q

What is a spin lock, and where is it commonly used?

A

A spin lock is a type of busy waiting mechanism.

Spin lock is use to hold a lock while waiting for it to become available.

It is commonly used at the kernel level in operating system with special hardware instructions.

44
Q

What is the drawbacks in busy waiting?

A
  • Wastes CPU resources
  • May prevent the lock-holding process from completing its critical section and releasing the lock.
45
Q

What is the drawbacks in busy waiting?

A
  • Wastes CPU resources
  • May prevent the lock-holding process from completing its critical section and releasing the lock.
46
Q

What is strict alternation in busy waiting?

A

Strict alternation enforces turn-taking between two processes for accessing the critical section.

  1. Shared Variable (Token): Represents the process ID of the next process allowed to enter the critical section
  2. Entry to critical section: Process Pi waits (busy-waits) until token == i (its process ID)
  3. Exit the Critical Section: Process Pi sets token to the next process ID, allowing the other processes to proceed.
47
Q

What are the limitation of strict alternation in concurrency?

A
  1. Inefficiency: Processes may wait unnecessarily, even if the other process isn’t ready to enter its critical section.
  2. Deadlocks Potential: If a process halts or fails outside its critical section, the other process can be stuck waiting indefinitely
  3. Not Scalable: Only works efficiently for two processes; complex to implement for more.
48
Q

What is the main benefit of strict alternation in busy waiting?

A

Mutual exclusion is guaranteed!

  • Only one process can enter its critical section at a time, as controlled by the turn variable.
  • The process with the current token has exclusive access to the critical section.
49
Q

What is the likeness progression problem in strict alternation?

A
  1. Dependence on turn variable: Both processes rely on the turn variable to switch
  2. Problem:
    - If one process is held up in its non-critical section,it won’t’ update the turn variable.
    - This causes other process to block, leading to a lack of progress or responsiveness