Dealing With Contention easy
In multithreading, what is a 'Critical Section'?
- A The part of the code that handles errors.
- B A block of code that accesses shared resources (memory, file, DB) and must not be executed by more than one thread at a time.
- C The most important feature of the app.
- D The login screen.
Answer: B. A block of code that accesses shared resources (memory, file, DB) and must not be executed by more than one thread at a time.
This is the code protected by locks. It should be as short as possible to minimize contention.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- Why is 'Exponential Backoff' preferred over constant intervals for retries?
- What is the primary purpose of a Mutex (Mutual Exclusion) lock?
- Why does adding more threads sometimes *decrease* performance?
- In a Saga, if a Compensating Transaction (Undo) fails repeatedly due to contention, what is the last resort?
- In a database, what happens if Transaction A locks a row and Transaction B tries to modify the same row?
- A database restart causes thousands of application servers to instantly try to reconnect. This crashes the DB again. This is called: