Commit 5b7527b0 authored by Igor Chorazewicz's avatar Igor Chorazewicz
Browse files

concurrent_hash_map: fix possible deadlock in erase

Consider the following scenario (where A and B are in the same bucket):
thread 1:		thread 2:
find(acc1, A)
			erase(A)
find(acc2, B)

First, thread 1 takes lock on the bucket and then on element A.
Then, thread 2 takes a lock on the bucket and tries to lock element A
but it can't because thread 1 already locked it - this way thread 2 is blocked.
Next, thread 1 tries to lock the bucket but it can't because thread 2 holds it.
Neither thread can progress.

This patch fixes that by introducing the same algorithm as in lookup/insert.
When trying to lock element in erase we now spin in a loop doing try_acquire and
if we do not succeed after specified amount of time we drop bucket lock and try
whole operation again.
parent e3cf24f8
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment