Topic 11 – Context switching Flashcards

(92 cards)

1
Q

in regards to the context block:

this is a record of what state the process is in such as running, ready or blocked, it is used to decide how the process should be treated.

A

in regards to the context block what is the:

process state

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

in 7 steps describe how

buffer control is possible by using a semaphore

A

the steps that describe this are:

  1. a buffer is empty and has a size of 10 (the semaphore value is 10)
  2. a process wishes to deposit an item so makes a SEM_WAIT system call
  3. since the semaphore is not 0 the process can deposit the item in the buffer
  4. the semaphore value is now decremented to 9
  5. steps 2 - 5 will reapeat untill the semaphore reaches 0
  6. a process wishes to deposit an item so makes a SEM_WAIT system call
  7. the semaphor count is 0 and so the process is put into a waiting state until another process removes an item from the buffer and makes the system call SEM_SIGNAL so that the semaphore can be incremented by 1

note

this example does not take into account an event such as two threads colliding at a buffer address (race condition) for this to be mitigated a seperate semaphore would be needed for mutual exclusion (mutex)

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

the main feature of the processor that the operating system takes advantage of to achieve this is:

the fact that a hardware interrupt will pause the execution of any process then switch to kernel mode and hand control of the CPU to the operating system

the hardware interrupt in question is received from a hardware timer

A

what is the main feature of the processor that the operating system takes advantage of to achieve

pre-emptive multitasking

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

describe in 5 steps the

stack pointer

during an interrupt without a context switch

A

this without a context switch

  1. an interrupt occurs
  2. process A instruction pointer is placed on top the stack pointer
  3. the routine is placed inside the instruction pointer and is executed
  4. when the routine is finished it will call the RETURN instruction
  5. process A instruction pointer is pulled of the stack pointer and execution commences where it was paused
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

in regards to the context block:

this records information such as a processes running time (quantum) and other information that can be used by the scheduler so that it can decide the order of execution

A

in regards to the context block what is the:

process priority

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

what are the two actions that can occur that would

cause a process to be transitioned and control of the CPU handed back to the operating system

A

these actions include:

  1. Transition because of a system call: for example when an application program makes an I/O request or goes to sleep
  2. Transition because of an interrupt: for example when the hardware timer interrupts

For either of these the process will change state and the OS will handle the events

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

two use cases of this are:

  1. mutual exclusion (mutex) - this can be used by a thread to tell other threads that it is currently executing a critical region of code and that the resource must not be acceessed this avoids scenerios such as a race condition
  2. buffer control - this can also be used as a counter for example how many units are available in a buffer
A

name 2 uses of the

semaphore

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

name 6 pieces of information that would be found in the

context block

for a process

A

this would record details for a process such as:

  • Process Identifier (PID)
  • the process state
  • the process priority
  • saved register contents
  • information about the processes memory space
  • information about files
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

while the processor is in kernel mode what 2 items does the operating system have access to

A

while the processor is in this mode the opearting system can access:

  • all instructions including privileged instructions
  • all data structures including the context block
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

in summary these problems occure when:

  1. There is a shared resource
  2. There are critical regions of code acting on those shared resources
A

in two summary points when do Concurrency problems such as the race condition occur

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

this system call essentially asks the OS if it can enter a critical region of code. If the semaphore count is 0 then the process is placed into a waiting state. If the semaphore count is not 0 then the semaphore count is set to 0 and the process enters a critical region of code

A

describe the semaphore system call

SEM_WAIT

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

with this type of state the operating system knows that the process is currently using the CPU

A

if a

process is in a running state

what does the operating system know about the process

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

these actions include:

  1. Transition because of a system call: for example when an application program makes an I/O request or goes to sleep
  2. Transition because of an interrupt: for example when the hardware timer interrupts

For either of these the process will change state and the OS will handle the events

A

what are the two actions that can occur that would

cause a process to be transitioned and control of the CPU handed back to the operating system

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

this would record details for a process such as:

  • Process Identifier (PID)
  • the process state
  • the process priority
  • saved register contents
  • information about the processes memory space
  • information about files
A

name 6 pieces of information that would be found in the

context block

for a process

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

if a process is in this state then the operating system knows that it is waiting on an I/O operation to complete

A

if a

process is in a blocked state

what does the operating system know about the process

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

this can only occur after a system call has been made or a hardware interrupt signal has been received.

in either case the processor will switch to kernel mode and the OS will gain control of the CPU, allowing it a chance to check the quantum of any running processes and run its scheduler if any quantum has expired

A

when can context switching occur

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

describe the semaphore system call

SEM_SIGNAL

A

this system call essentially tells the operating system that it is finished executing its critical region of code and the semaphore count can be incremented so that another process may enter its critical region of code.

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

this is a place in the source code that acts on a shared resource. If these actions are not carried out correctly and in full then the value of the shared resource could become false

A

what is a

critical region

of code

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

this is a solution to multitasking

within this solution the operating system has control over when it will use the CPU.

it does this by setting a hardware timer that will interrupt any process

A

describe what

pre-emptive multitasking

is

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

this is the term given to a semaphore when it is used for the purpose of mutual exclusion

note

semaphores have many use cases within the operating system

A

what is a

mutex

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

in regards to the context block what is the:

process priority

A

in regards to the context block:

this records information such as a processes running time (quantum) and other information that can be used by the scheduler so that it can decide the order of execution

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

this is the act of the currently running process being replaced by another process

note

since all data within the CPU registers will be replaced it is said that the CPU is now executing in a different “context”

A

what is

context switching

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

if a

process is in a ready state

what does the operating system know about the process

A

if a process is in this state then the operating system knows that it is waiting to be rescheduled to use the CPU

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

execpt for the semaphore system calls SEM_WAIT and SEM_SIGNAL

what other system calls are there that are associatied with the semaphore

A

There are also system calls that allow the creation and destroying of different semaphores so that different semaphores can be used by different applications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
this is a diagram that expresses the transition and states of a process. * ovals show the state of a process * arrows show the direction and transition of a process from one state to another _notes_ * All states and transitions should be labelled with there appropriate state or transition. * These are important for design as well as understanding
describe a ## Footnote **state diagram and its components**
26
in regards to the context block what is the: ## Footnote **Information about the process’s memory space**
in regards to the context block: this is information about what memory the process has allocated to it. information recorded would include the address range of the memory
27
the steps include: 1. Process A running 2. Process A makes SEM\_WAIT system call 3. Semaphore count is 0 4. Process A placed in waiting state 5. Process B makes SEM\_SIGNAL system call 6. Semaphore count is incremented by 1 7. Process A state changed from waiting to ready 8. Semaphore count set to 0 9. Process A is rescheduled and runs its critical code 10. Process A finishes and makes SEM\_SIGNAL system call 11. Semaphore count is incremented by 1 If step 3 had a count of 1 then execution would jump to step 8
describe in 11 steps what happens when: 1. process B is running critical code on a resource 2. process A tries to access the same resource and a mutex is in use by both processes
28
this works in the following steps: 1. the opearating system has control of the CPU 2. it will set a hardware timer 3. a new process is scheduled to use the CPU 4. the hardware timer sends a hardware interrupt signal to the processor 5. the processor switches to kernel mode and the interrupt service routine for the timer is executed on the CPU 6. since the interrupt service routine for the timer is part of the operating system it can call on the scheduler if any process in a running state has quantum that has expired
describe how **pre-emptive multitasking** works in 6 steps
29
two purposes of this are: 1. **for use by the scheduler** - so that it can determine which process should be executed next 2. **for use during a context switch** - so that a state of a process can be restored or saved (such as the state of registers or the memory a process has allocated to it)
name 2 purposes for the ## Footnote **context block**
30
name 1 benefit and disadvantage of ## Footnote **pre-emptive multitasking**
a benefit of this is: If code is buggy or malicious then the operating system will always be able to regain control of the CPU a disadvantage of this is: that a process could be interrupted at a critical point in its execution and data could be left inconsistent. this is especially true of concurrent processes that are sharing data (race condition)
31
describe in 8 steps the **stack pointer** during an interrupt **with** a context switch
this **with** a context switch 1. an interrupt occurs 2. process A has its instruction pointer placed on top the stack pointer 3. the routine is placed inside the instruction pointer and executed 4. the routine detects that process A has expired quantum and the OS scheduler is called 5. the operating system must make a context switch from process A to process B 6. the stack pointer register has its contents changed, now the stack pointer holds process B stack pointer 7. the routine finishes execution and calls the RETURN instruction 8. process B instruction pointer is pulled of the stack pointer and into the instruction pointer and execution commences where it was paused
32
this is a phenomenon that occurs when two or more concurrent threads are sharing a resource its a problem that lies where they both are carrying out tasks on that resource but neither has finished its task fully the outcome is that depending on the order of who fnishes arrying out the task on that resource determines the final value of that resource the final value of the resource will most likely be incorrect
describe what the **race condition** is
33
if a process is in this state then the operating system knows that it is waiting to be rescheduled to use the CPU
if a **process is in a ready state** what does the operating system know about the process
34
outline the state of a process and any transitions for the following sceneraio **a process makes an I/O system call where it will be blocked and then rescheduled**
for this scenerio the steps are as follows: 1. the process A is in a running state 2. the process A makes an I/O system call to the operating system 3. processor mode switches to kernel mode 4. the operating system foresees the I/O operation taking some time 5. the process A is placed in a blocked state 6. a context switch occurs and another process is given control of the processor 7. processor mode switches to user mode 8. a hardware interrupt is received by the processor from the I/O device telling the processor that it is ready 9. processor mode switches to kernel mode 10. context switch occurs and the interrupt service routine for the I/O device is executed 11. the process A is unblocked and placed into a ready state until it is rescheduled
35
what is a ## Footnote **semaphore**
this is a service that is built into the operating system. this enables the control and access of a shared resource so that threads sharing such a resource can avoid errors such as a race condition
36
what is ## Footnote **context switching**
this is the act of the currently running process being replaced by another process _note_ since all data within the CPU registers will be replaced it is said that the CPU is now executing in a different "context"
37
these signals are sent to the processor by an I/O device. telling the processor that it is ready to either send or recieve data
when are **hardware interrupt signals** sent to the processor
38
name 2 uses of the ## Footnote **semaphore**
two use cases of this are: 1. **mutual exclusion (mutex)** - this can be used by a thread to tell other threads that it is currently executing a critical region of code and that the resource must not be acceessed this avoids scenerios such as a race condition 2. **buffer control** - this can also be used as a counter for example how many units are available in a buffer
39
the operating system stores these inside of main memory and they are updated for each process whenever it makes a transition from a running state to any non running state
where does the ## Footnote **operating sytem store each context block for a process and when does each get updated**
40
this **without** a context switch 1. an interrupt occurs 2. process A instruction pointer is placed on top the stack pointer 3. the routine is placed inside the instruction pointer and is executed 4. when the routine is finished it will call the RETURN instruction 5. process A instruction pointer is pulled of the stack pointer and execution commences where it was paused
describe in 5 steps the **stack pointer** during an interrupt **without** a context switch
41
methods that will accomplish this are: * Cooperative multitasking * Pre-emptive multitasking
what are 2 methods that ## Footnote **ensure that the operating system can always gain back control of a processor so that it can carry out its own tasks such as scheduling**
42
where does the ## Footnote **operating sytem store each context block for a process and when does each get updated**
the operating system stores these inside of main memory and they are updated for each process whenever it makes a transition from a running state to any non running state
43
this **with** a context switch 1. an interrupt occurs 2. process A has its instruction pointer placed on top the stack pointer 3. the routine is placed inside the instruction pointer and executed 4. the routine detects that process A has expired quantum and the OS scheduler is called 5. the operating system must make a context switch from process A to process B 6. the stack pointer register has its contents changed, now the stack pointer holds process B stack pointer 7. the routine finishes execution and calls the RETURN instruction 8. process B instruction pointer is pulled of the stack pointer and into the instruction pointer and execution commences where it was paused
describe in 8 steps the **stack pointer** during an interrupt **with** a context switch
44
in regards to the context block: this is information about what memory the process has allocated to it. information recorded would include the address range of the memory
in regards to the context block what is the: ## Footnote **Information about the process’s memory space**
45
in 4 points how can a ## Footnote **race condition be avoided**
this can be avoided by: * identifiying shared resources * identifying critical code using those shared resources * employing methods that allow a thread to execute its critical code without being distured (semaphore) * employ methods that allow a thread exclusive access to a shared resource while it is carrying out critical code (semaphore)
46
in regards to the context block what is the: ## Footnote **process state**
in regards to the context block: this is a record of what state the process is in such as running, ready or blocked, it is used to decide how the process should be treated.
47
what are 2 methods that ## Footnote **ensure that the operating system can always gain back control of a processor so that it can carry out its own tasks such as scheduling**
methods that will accomplish this are: * Cooperative multitasking * Pre-emptive multitasking
48
in the context of a race condition this can ensure that: only one thread can be executing critical code on a shared resource at a time this guarantees that a race condition cannot occur
in the context of a race condition what can a ## Footnote **semaphore ensure**
49
in regards to the context block: this is a record of any open files that a process may have open and that the operating system needs to keep track of
in regards to the context block what is the: ## Footnote **Information about files**
50
in regards to the context block: this uniquely identifies a process
in regards to the context block what is the ## Footnote **Process Identifier (PID)**
51
what are 3 problems that arise from **context switching** which must always be solved to enable multitasking
3 problems that arise from this are: * The first is to ensure that the OS itself is executing when a context switch is required * second is what information about a process must be saved so that it can be stopped and restarted * third is how to cleanly switch the processor from executing one process to executing another
52
when are **hardware interrupt signals** sent to the processor
these signals are sent to the processor by an I/O device. telling the processor that it is ready to either send or recieve data
53
this is a service that is built into the operating system. this enables the control and access of a shared resource so that threads sharing such a resource can avoid errors such as a race condition
what is a ## Footnote **semaphore**
54
There are also system calls that allow the creation and destroying of different semaphores so that different semaphores can be used by different applications
execpt for the semaphore system calls SEM\_WAIT and SEM\_SIGNAL ## Footnote **what other system calls are there that are associatied with the semaphore**
55
if a **process is in a blocked state** what does the operating system know about the process
if a process is in this state then the operating system knows that it is waiting on an I/O operation to complete
56
name 2 ## Footnote **disadvantages of Cooperative multitasking**
disadvantages of this include: 1. **process hogging** - programmers could choose to hold on to the CPU for longer than they should so that they can gain extra performance at the benefit of other processes 2. **buggy programs** - A buggy application that never reaches a point where control would be yielded back to the operating system such as being stuck in a loop. would potentially mean that the system would crash since the operating system cannot regain control of the CPU and make any recoveries
57
in regards to the context block: this is the contents of the CPU registers that was stored for the process when a context switch occured saved data would include: * stack pointer register * instruction pointer register * status register
in regards to the context block what is the: ## Footnote **saved register contents**
58
give an example of a race condition where the shared resource is a bank balance and thread A is depositing 100 and thread B is withdrawing 100
an example of this would be: 1. thread A reads the bank balance at 500 2. a context switch occurs 3. thread B raeds the banks balance at 500 4. a context switch occurs 5. thread A adds 100 to the 500 and updates the balance to 600 6. a context switch occurs 7. thread B subtracts 100 from the 500 and updates the balance to 400 the final balance is 400 when it should still be 500. this occured because thread A could not finish its critical code before the context switch
59
this can be avoided by: * identifiying shared resources * identifying critical code using those shared resources * employing methods that allow a thread to execute its critical code without being distured (semaphore) * employ methods that allow a thread exclusive access to a shared resource while it is carrying out critical code (semaphore)
in 4 points how can a ## Footnote **race condition be avoided**
60
describe what **Cooperative multitasking** is
this is a solution that enables multitasking it involves all application programs to be written in such a way that they will periodically yield control of the CPU back to the operating system so that it can be rescheduled and other processes can use the CPU.
61
how many processors are operating systems designed to run on
these are designed to run on one processor. they are software just like any application program and must share control of the resources available. the crucial difference is that this has the responsibility to orchestrate the use of resources correctly and efficiently
62
in regards to the context block what is the: ## Footnote **Information about files**
in regards to the context block: this is a record of any open files that a process may have open and that the operating system needs to keep track of
63
when can **context switching** occur
this can only occur after a system call has been made or a hardware interrupt signal has been received. in either case the processor will switch to kernel mode and the OS will gain control of the CPU, allowing it a chance to check the quantum of any running processes and run its scheduler if any quantum has expired
64
in regards to the context block what is the ## Footnote **Process Identifier (PID)**
in regards to the context block: this uniquely identifies a process
65
3 problems that arise from this are: * The first is to ensure that the OS itself is executing when a context switch is required * second is what information about a process must be saved so that it can be stopped and restarted * third is how to cleanly switch the processor from executing one process to executing another
what are 3 problems that arise from **context switching** which must always be solved to enable multitasking
66
what is a ## Footnote **critical region** **of code**
this is a place in the source code that acts on a shared resource. If these actions are not carried out correctly and in full then the value of the shared resource could become false
67
disadvantages of this include: 1. **process hogging** - programmers could choose to hold on to the CPU for longer than they should so that they can gain extra performance at the benefit of other processes 2. **buggy programs** - A buggy application that never reaches a point where control would be yielded back to the operating system such as being stuck in a loop. would potentially mean that the system would crash since the operating system cannot regain control of the CPU and make any recoveries
name 2 ## Footnote **disadvantages of Cooperative multitasking**
68
what is the main feature of the processor that the operating system takes advantage of to achieve ## Footnote **pre-emptive multitasking**
the main feature of the processor that the operating system takes advantage of to achieve this is: the fact that a hardware interrupt will pause the execution of any process then switch to kernel mode and hand control of the CPU to the operating system the hardware interrupt in question is received from a hardware timer
69
describe the semaphore system call **SEM\_WAIT**
this system call essentially asks the OS if it can enter a critical region of code. If the semaphore count is 0 then the process is placed into a waiting state. If the semaphore count is not 0 then the semaphore count is set to 0 and the process enters a critical region of code
70
the steps that describe this are: 1. a buffer is empty and has a size of 10 (the semaphore value is 10) 2. a process wishes to deposit an item so makes a SEM\_WAIT system call 3. since the semaphore is not 0 the process can deposit the item in the buffer 4. the semaphore value is now decremented to 9 5. steps 2 - 5 will reapeat untill the semaphore reaches 0 6. a process wishes to deposit an item so makes a SEM\_WAIT system call 7. the semaphor count is 0 and so the process is put into a waiting state until another process removes an item from the buffer and makes the system call SEM\_SIGNAL so that the semaphore can be incremented by 1 _note_ this example does not take into account an event such as two threads colliding at a buffer address (race condition) for this to be mitigated a seperate semaphore would be needed for mutual exclusion (mutex)
in 7 steps describe how ## Footnote **buffer control is possible by using a semaphore**
71
This is a snapshot or a record of every process and its state that must be known about by the operating system
what is the ## Footnote **context block**
72
while the processor is in this mode the opearting system can access: * all instructions including privileged instructions * all data structures including the context block
while the processor is in kernel mode what 2 items does the operating system have access to
73
name 2 purposes for the ## Footnote **context block**
two purposes of this are: 1. **for use by the scheduler** - so that it can determine which process should be executed next 2. **for use during a context switch** - so that a state of a process can be restored or saved (such as the state of registers or the memory a process has allocated to it)
74
this is a solution that enables multitasking it involves all application programs to be written in such a way that they will periodically yield control of the CPU back to the operating system so that it can be rescheduled and other processes can use the CPU.
describe what **Cooperative multitasking** is
75
in two summary points when do Concurrency problems such as the race condition occur
in summary these problems occure when: 1. There is a shared resource 2. There are **critical regions** of code acting on those shared resources
76
what is the ## Footnote **context block**
This is a snapshot or a record of every process and its state that must be known about by the operating system
77
these are designed to run on one processor. they are software just like any application program and must share control of the resources available. the crucial difference is that this has the responsibility to orchestrate the use of resources correctly and efficiently
how many processors are operating systems designed to run on
78
describe how **pre-emptive multitasking** works in 6 steps
this works in the following steps: 1. the opearating system has control of the CPU 2. it will set a hardware timer 3. a new process is scheduled to use the CPU 4. the hardware timer sends a hardware interrupt signal to the processor 5. the processor switches to kernel mode and the interrupt service routine for the timer is executed on the CPU 6. since the interrupt service routine for the timer is part of the operating system it can call on the scheduler if any process in a running state has quantum that has expired
79
an example of this would be: 1. thread A reads the bank balance at 500 2. a context switch occurs 3. thread B raeds the banks balance at 500 4. a context switch occurs 5. thread A adds 100 to the 500 and updates the balance to 600 6. a context switch occurs 7. thread B subtracts 100 from the 500 and updates the balance to 400 the final balance is 400 when it should still be 500. this occured because thread A could not finish its critical code before the context switch
give an example of a race condition where the shared resource is a bank balance and thread A is depositing 100 and thread B is withdrawing 100
80
if a **process is in a running state** what does the operating system know about the process
with this type of state the operating system knows that the process is currently using the CPU
81
in regards to the context block what is the: ## Footnote **saved register contents**
in regards to the context block: this is the contents of the CPU registers that was stored for the process when a context switch occured saved data would include: * stack pointer register * instruction pointer register * status register
82
what is a ## Footnote **mutex**
this is the term given to a semaphore when it is used for the purpose of mutual exclusion _note_ semaphores have many use cases within the operating system
83
for this scenerio the steps are as follows: 1. the process A is in a running state 2. the process A makes an I/O system call to the operating system 3. processor mode switches to kernel mode 4. the operating system foresees the I/O operation taking some time 5. the process A is placed in a blocked state 6. a context switch occurs and another process is given control of the processor 7. processor mode switches to user mode 8. a hardware interrupt is received by the processor from the I/O device telling the processor that it is ready 9. processor mode switches to kernel mode 10. context switch occurs and the interrupt service routine for the I/O device is executed 11. the process A is unblocked and placed into a ready state until it is rescheduled
outline the state of a process and any transitions for the following sceneraio **a process makes an I/O system call where it will be blocked and then rescheduled**
84
this system call essentially tells the operating system that it is finished executing its critical region of code and the semaphore count can be incremented so that another process may enter its critical region of code.
describe the semaphore system call SEM\_SIGNAL
85
in this case it can guarantee mutual exclusion that is that only one process can be executing a critical region of code at the same time. this in turn can mitigate a race problem
when two values are being used for a semaphore ## Footnote **what can the semaphore guarantee**
86
a benefit of this is: If code is buggy or malicious then the operating system will always be able to regain control of the CPU a disadvantage of this is: that a process could be interrupted at a critical point in its execution and data could be left inconsistent. this is especially true of concurrent processes that are sharing data (race condition)
name 1 benefit and disadvantage of ## Footnote **pre-emptive multitasking**
87
describe in 11 steps what happens when: 1. process B is running critical code on a resource 2. process A tries to access the same resource and a mutex is in use by both processes
the steps include: 1. Process A running 2. Process A makes SEM\_WAIT system call 3. Semaphore count is 0 4. Process A placed in waiting state 5. Process B makes SEM\_SIGNAL system call 6. Semaphore count is incremented by 1 7. Process A state changed from waiting to ready 8. Semaphore count set to 0 9. Process A is rescheduled and runs its critical code 10. Process A finishes and makes SEM\_SIGNAL system call 11. Semaphore count is incremented by 1 If step 3 had a count of 1 then execution would jump to step 8
88
in the context of a race condition what can a ## Footnote **semaphore ensure**
in the context of a race condition this can ensure that: only one thread can be executing critical code on a shared resource at a time this guarantees that a race condition cannot occur
89
describe what **pre-emptive multitasking** is
this is a solution to multitasking within this solution the operating system has control over when it will use the CPU. it does this by setting a hardware timer that will interrupt any process
90
describe a ## Footnote **state diagram and its components**
this is a diagram that expresses the transition and states of a process. * ovals show the state of a process * arrows show the direction and transition of a process from one state to another _notes_ * All states and transitions should be labelled with there appropriate state or transition. * These are important for design as well as understanding
91
describe what the **race condition** is
this is a phenomenon that occurs when two or more concurrent threads are sharing a resource its a problem that lies where they both are carrying out tasks on that resource but neither has finished its task fully the outcome is that depending on the order of who fnishes arrying out the task on that resource determines the final value of that resource the final value of the resource will most likely be incorrect
92
when two values are being used for a semaphore ## Footnote **what can the semaphore guarantee**
in this case it can guarantee mutual exclusion that is that only one process can be executing a critical region of code at the same time. this in turn can mitigate a race problem