← 返回 netflix 的题目列表Implement an Atomic Counter (Thread-Safe Counter)
类型:online_judge
Implement a thread-safe counter AtomicCounter.
APIs
increment() -> int: atomically increments by 1 and returns the new value.
get() -> int: returns the current value.
Requirements
Using synchronized (or equivalent mutex) is allowed.
Discuss performance bottlenecks under high contention and possible optimizations (CAS/LongAdder) verbally.
Scale
100+ threads, up to 1e6 total operations.
Example
Input
2 threads each increment 100000 times
Output
final get() == 200000