troydhanson / uthash

C macros for hash tables and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to handle lock on HASH_ITER?

goog opened this issue · comments

if i have 200 hash kv items, so the read lock will may take a long time, is therer a better way?

pthread_rwlock_rdlock(&lock);
HASH_ITER(hh,p_device_hash,current_element,tmp)
pthread_rwlock_unlock(&lock);

That's a question about multithreaded design patterns, not a question about uthash.
The "right" answer will depend on your workload: How many threads are taking the read lock? how often? why? How many threads are taking the write lock? how often? why? For what purpose are you iterating over the entire hash? Could you make a copy of the hash and iterate over that copy instead? Could you use HASH_FIND instead of HASH_ITER? etc. etc. etc.
And all of that design work is idiosyncratic to your specific project; there's nothing uthash can do to help you with it.