0
0
LLDsystem_design~20 mins

Thread safety in design in LLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Thread Safety Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2: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?
ATo prevent threads from reading stale data by ensuring exclusive access during updates
BTo increase the speed of thread execution by allowing simultaneous writes
CTo allow threads to skip resource access if another thread is using it
DTo reduce memory usage by sharing locks among unrelated resources
Attempts:
2 left
💡 Hint
Think about what happens if two threads write to the same data at the same time.
Architecture
intermediate
2: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?
AUse an atomic increment operation provided by the hardware or language runtime
BUse a simple integer variable without synchronization
CUse a global lock but only lock during reads, not writes
DUse separate counters per thread without combining results
Attempts:
2 left
💡 Hint
Consider how to avoid race conditions when multiple threads update the same value.
scaling
advanced
2: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?
AUse a single lock but increase its timeout to reduce waiting
BPartition the cache into multiple segments, each with its own lock
CRemove all locks and rely on eventual consistency
DUse a global lock but only lock during cache misses
Attempts:
2 left
💡 Hint
Think about dividing work to reduce contention.
tradeoff
advanced
2: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?
ALock-free designs guarantee better performance in all scenarios
BLock-free designs always use more memory and are slower than lock-based ones
CLock-based designs never cause deadlocks or performance issues
DLock-free designs reduce blocking but are often more complex to implement and debug
Attempts:
2 left
💡 Hint
Consider complexity and debugging challenges.
estimation
expert
2: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?
A400 operations per second
B1600 operations per second
C200 operations per second
D800 operations per second
Attempts:
2 left
💡 Hint
Calculate how many operations fit in one second considering the lock is exclusive.