Protecting Each index of shared memory arry with a semaphore

41 Views Asked by At

I want to simulate supermarket shelves where each would have a certain number of items, and I am going to put each into an index in an array that is shared memory between many processes and threads, I want to be able to only lock one item at a time so I thought about protecting each "shelf" individually instead of protecting the whole array, so I would have one mutex for each index.

Can I do this without causing problems with the array or causing race conditions?

0

There are 0 best solutions below