[dpdk-dev] Question regarding concurrency and hash table

Vladimir Medvedkin medvedkinv at gmail.com
Mon May 12 11:18:18 CEST 2014


Hi,

Programmer's guide section 22.1:
<quote>
The hash and LPM libraries are, by design, thread unsafe in order to
maintain performance. However, if required the developer can add layers on
top of these libraries to provide thread safety. Locking is not needed in
all situations, and in both the hash and LPM libraries, lookups of values
can be performed in parallel in multiple threads. Adding, removing or
modifying values, however, cannot be done in multiple threads without using
locking when a single hash or LPM table is accessed. Another alternative to
locking would be to create multiple instances of these tables allowing each
thread its own copy.
</quote>

So, rte_hash_add_key() is not multi-thread safe unlike the
rte_hash_lookup() which is multi-thread safe. You can call add and lookup
func simultaneously if you make sure that rte_hash_add_key() call either
from single dedicated thread or protect by lock hash table.


2014-05-12 12:29 GMT+04:00 Tomas Vestelind <Tomas.Vestelind at hiq.se>:

> Hello all!
>
> I have a question regarding the possible concurrency issues in hash table.
> My questions is:
> Is it possible to call rte_hash_add() and rte_hash_lookup() at the same
> time without data inconsistency?
>
> My guess is that I need to use a lock as protection. I see that you have a
> couple of nice ones :)
>
> BR,
> Tomas Vestelind
>


More information about the dev mailing list