I am thinking here: If you have 2 threads executing FAST operations that need to be synchronized, isn’t a nonblocking approach faster/better than a blocking/context switch approach?
By non-blocking I mean something like:
while(true) {
if (checkAndGetTheLock()) break;
}
The only thing I can think of is starvation (with CPU burn out) if you have too many threads looping around the lock.
How do I balance one approach versus the other?
Here’s what Java Concurrency in Practice says about the subject:
And also (which is, IMO, the most important point):