I have a very big array read/write by several threads. Each thread will only rw one element of them at a time, so it would be a bad idea to lock the whole array. What I am expecting is something like
// before threads
lock_t Lock[NUM_THREADS];
...
// during threads
get_lock(Lock[thread_id], element_id);
array[element_id]+=10; // some operations
release_lock(Lock[thread_id]);
So my question is, what is the best strategy of designing get_lock
and release_lock
?