Challenge - 5 Problems
Thread Safety Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding Thread Safety in Shared Resource Access
In a multi-threaded system, what is the main reason to use locks when multiple threads access a shared resource?
Attempts:
2 left
💡 Hint
Think about what happens if two threads write to the same data at the same time.
✗ Incorrect
Locks ensure that only one thread can modify or read the shared resource at a time, preventing inconsistent or corrupted data.
❓ Architecture
intermediate2:00remaining
Designing a Thread-Safe Counter
You need to design a thread-safe counter that multiple threads can increment concurrently without losing updates. Which design choice ensures correctness?
Attempts:
2 left
💡 Hint
Consider how to avoid race conditions when multiple threads update the same value.
✗ Incorrect
Atomic operations guarantee that increments happen without interruption, preventing lost updates.
❓ scaling
advanced2:00remaining
Scaling a Thread-Safe Cache System
You have a cache accessed by many threads. Using a single global lock causes contention and slows down the system. Which design improves scalability while maintaining thread safety?
Attempts:
2 left
💡 Hint
Think about dividing work to reduce contention.
✗ Incorrect
Segmenting the cache reduces lock contention by allowing parallel access to different parts.
❓ tradeoff
advanced2:00remaining
Choosing Between Locking and Lock-Free Designs
Which is a key tradeoff when choosing a lock-free data structure over a lock-based one?
Attempts:
2 left
💡 Hint
Consider complexity and debugging challenges.
✗ Incorrect
Lock-free designs avoid blocking but require careful design to avoid subtle bugs and are harder to maintain.
❓ estimation
expert2:00remaining
Estimating Maximum Throughput with Locks
A system has 8 threads accessing a shared resource protected by a single lock. Each thread holds the lock for 5 milliseconds per operation. Assuming no other delays, what is the maximum number of operations per second the system can perform?
Attempts:
2 left
💡 Hint
Calculate how many operations fit in one second considering the lock is exclusive.
✗ Incorrect
Since the lock is exclusive, only one thread can operate at a time. Each operation takes 5 ms, so 1000 ms / 5 ms = 200 operations per second.