class Counter {
ReentrantLock l = new ReentrantLock();
private int n = 0;
void inc() {
l.lock();
try {
n++;
} finally {
l.unlock();
}
}
}
--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "mechanical-sympathy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mechanical-sympathy/Tm3xRcvpnzE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mechanical-symp...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "mechanical-sympathy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mechanical-sympathy/Tm3xRcvpnzE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mechanical-symp...@googlegroups.com.
The definition is weird
" always at least one thread is making progress."
That's always the case... Otherwise it's dead-lock :)
I would call a lock-free algo, an algo that never parks a thread.
Lock() does CAS and a few think then park to OS scheduler if fails.
Wait-free is even more interesting to define :)
My 2 cents
I don't think this is the definition for lock-free.If I understand you correctly, you essentially require any thread to finish its work in constant amount of steps. Why do I say any thread? Because the adversarial scheduler can choose to run any of the threads alone, and you still expect system wide progress.
To my understanding this is the definition of wait-free, not lock free.
There is something magical about CAS, at least according to The Art Of Multiprocessor Programming. This instruction have consensus number of infinity, and hence can be used to generate lock-free and wait-free objects from any object.