Slides 8 Flashcards

1
Q

Define Race Condition

A

is a behavior where the output is dependent on the sequence or timing of other uncontrollable events (eg. context switching, scheduling on multiple CPUs)

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

What are some examples of race conditions?

A

modifying shared memory
• reading/writing to files
• modifying filesystems
• reading/writing to databases

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

If int x = counter;
x = x + 1;
counter = x; causes a race condition would replacing these 3 lines with counter ++; get rid of the race condition?

A

No because ++ is still 3 instructions in assembly and thus the modified data isn’t guaranteed to happen after each other instead of during

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

Define Critical section

A

part of the program that accesses the shared resource in a part of the program that access the shared resource in a way that could lead to races or other undefined/unpredictable/unwanted behaviour

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

What are the 4 requirements for a good, race-free solution?

A
  1. Mutual exclusion: No two processes/threads may be simultaneously inside their critical sections (CS)
  2. Progress: No process/threads running outside its CS may block other processes/threads.
  3. Bounded waiting: No process/thread should have to wait forever to enter its CS.
  4. Speed: No assumptions may be made about the speed or the number of CPUs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a problem with asynchronous thread cancellation?

A

killed thread has no chance to “clean up”

• this can (likely) lead to leaving data in undefined state

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