I am allocating memory using mmap
to store some data in set associative manner where I want to access sets concurrently. So, if there are K sets then I am allocating K+1 slots per set where first slot is used for metadata. Here at start of metadata slot I want to store a lock. So how do I create a lock at this specific location? I found using sizeof operator that size of lock is 40B. So I made sure each entry is atleast 40B.
Normally, we create pthread lock using
pthread_mutex_t lock;
So, is it safe to just copy 40B of lock variable to required location?
As it is difficult to debug concurrent program it will be great if someone can tell if it is right way to do it. Thank you.