← 返回 netflix 的题目列表Double-Checked Locking / Locking Correctness in Multithreaded Code
类型:online_judge
In a multithreaded environment, implement/fix shared object initialization to be thread-safe while minimizing locking overhead.
Requirements
Implement getInstance() for a singleton: create on first call, return the same instance afterwards.
Discuss and avoid classic double-checked locking pitfalls (e.g., reordering causing a partially constructed object to be observed).
What to cover
What is a correct implementation under the target language/memory model (e.g., Java/C++)?
Alternative approaches (static init, Initialization-on-demand holder, CAS, etc.).
Example
Input
100 threads concurrently call getInstance() 1000 times each
Output
all returned references should be identical