In my understanding
block is there are =1 task could progress if there are N tasks concurrent running
and one enter the critical area(enter the critical area one).
lock-free is there are >=1 tasks could progress if there are N tasks concurrent
running and one enter the critical area.
wait-free is there are N tasks could progress if there are N tasks concurrent
running and one enter the critical area(maybe it shouldn't be called `critical area`).
My questions is:
If a hash table have N buckets, and each one has a lock, in any time, there should be >=1 tasks could in progress. Is this type hash table could be defined lock-free?
bucket
+-------------+ +-------+ +-------+
| head | lock | ---> | entry | ---> | entry | ---> ...
+-------------+ +-------+ +-------+
No. "each one has a lock" implies potential blocking. As a test for "lock free", consider whether a suspended thread could prevent another thread from making progress for the entire time it's suspended. If so, then it's not a lock free situation.
In lock free programming you use something like an atomic operation - often with a spin on update failure - such that a thread attempting to make progress may have to retry but each time there's a new race condition to see whether they progress; they're in with a genuine chance.
Spin locks
(I put some details in comments, but that was getting clumsy.)
"Spin lock" means different things to different people.
Historically, some people called a mutex or read-write lock a spin lock if it at least span a few (hundred/thousand) times trying to atomically acquire the lock before joining an OS queue for that lock (so it won't keep burning CPU if the thread holding the lock runs for a long time).
Microsoft at http://msdn.microsoft.com/en-us/library/ms894034.aspx use it in a different way:
So, in that context they deem a spin lock to be akin to the usage I describe above, but have no provision for falling back on an event-driven queue to avoid burning CPU time.
Lock-free atomic operations tend to be spinning too - the difference is that they've completed their work when the spinning stops, rather than having shut out competing threads to allow them to begin the work (and having those competing threads blocked from progress even if the locking thread gets suspended or delayed in some way).