Hard to Detect Programming errors Flashcards
When do race conditions occur?
They occur when multiple threads share the same variable.
What is the solution for race conditions?
Form group of shared variables between threads, such that variables in different groups can be changed independently without affecting the correctness of the system.
What must critical regions for the same group of shared variables have to be?
Mutually exclusive
What is keyword synchronized for race conditions?
A keyword that ensure only one thread can execute a particular block of code or method at a time.
What is the critical region?
A segment of a program where shared resources are accessed or modified, where improper syntonisation can lead to race conditions and accidents.
Why are race conditions hard to detect?
They involve unpredictable interleaving of concurrent threads. It’s hard to replicate time specific scenarios.
When does aliasing occur?
Aliasing occurs when two or more variables in a program refer to the same memory location.
Give an example of an aliasing problem?
Trying to swap two variables around without an auxiliary variable e.g.
x = y
y = x
(This would not work)
What is an auxiliary variable?
A temporary variable.