In a system where multiple threads update a shared counter without synchronization, what is the most likely outcome?
Think about what happens when two threads try to update the same value at the same time.
Without synchronization, multiple threads can overwrite each other's updates, causing lost increments and incorrect counter values.
You have a shared resource accessed by multiple threads. Which synchronization mechanism is best to ensure only one thread accesses it at a time?
Think about how to prevent multiple threads from entering a critical section simultaneously.
A mutex (lock) ensures mutual exclusion, allowing only one thread to access the shared resource at a time, preventing race conditions.
You design a system where many users write data concurrently to a database. What is a common strategy to handle high write loads without causing contention?
Think about dividing the workload to avoid bottlenecks on one server.
Database sharding distributes data across multiple servers, allowing concurrent writes to different shards and reducing contention.
Which statement best describes a tradeoff between optimistic and pessimistic concurrency control?
Consider how each method handles conflicts and resource locking.
Optimistic concurrency control works well when conflicts are rare by allowing concurrent access and retrying on conflicts. Pessimistic control locks resources to prevent conflicts but can reduce concurrency and cause waiting.
A system has 10 threads trying to access a shared resource protected by a lock. Each thread holds the lock for 5 milliseconds per operation. Assuming no other delays, what is the maximum number of operations the system can perform per second?
Calculate how many operations fit in one second considering the lock is held exclusively.
Since only one thread can hold the lock at a time for 5 ms, each operation takes 5 ms. In one second (1000 ms), 1000 / 5 = 200 operations can be done sequentially. With 10 threads, they share the lock, but only one runs at a time, so total throughput is 200 ops/sec.
