Question

I am new to computer science and it may sound stupid to some of you. Although i have searched for related question, but this scenario stuck in my mind. I understand that Mutexes provide lock facility for a section or resource. Consider the example of a buffer(an array of size 10 say) where a thread puts some value in it. We lock the mutex before using it releases after. This whole process is done by same thread.

Now if i have to do this same process with semaphores. I can limit the number of threads that can enter the critical section in this case. But how can the integrity of the buffer is maintained. (read and write operations handled by different threads on buffer)

Was it helpful?

Solution

Semaphores are an higher abstraction. Semaphores controls the ability to create processes and make sure the instance created is distinct in which case it is kicked out. In a nutshell.

OTHER TIPS

The usual solution with semaphores is to allow multiple simultaneous readers or one writer. See the Wikipedia article Readers-writers problem for examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top