1/13
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is the similarity between sleep() and yield()?
Both let a thread pause without releasing its locks, and neither blocks on a condition.
The three states are Ready, Running, and Blocked. The scheduler swaps a thread between Ready and Running, and I/O or lock waits before sending it to blocked
Coarse-grained locking uses one lock for everything, but serializes all access. Fine-grained gives each element its own lock for more concurrency, at the cost of complexity.
What is the purpose of a synchronized block?
A synchronized block guarantees mutual exclusion and visibility between threads.
Explain how CompareAndSwap works?
CAS atomically compares a memory location to an expected value. If they match it swaps in new values. if not it does nothing and retires
When is it better than locks?
CAS is better than locks under light contention, since a failed thread just retries instead of blocking
two reasons threads are better than processes
Threads share memory directly, so no IPC is needed. Threads are also cheaper to create and context switch.
Why cant semaphores be used as locks, expect in one condition
No ownership check. Any thread can release, even one that never called acquire. Only safe as a lock when the same thread does both