Qualcomm Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
I think two of the readers (including shondik) didn't read the question, which states to _avoid_ mutual exclusion...
So -1.
Sorry, very true.. Was in a hurry & missed the point.
Does it make any sense to ask for avoiding mutual exclusion when there is only one resource?
As the question clearly states "one or many process try to access the queue"?
This support can be provided by Semaphore as it allows multiple process to enter and read the contents. And we can use "Mutex" which is kind of binary semaphore for writing.
Once the "Semaphore" count is zero one of the process can claim the "mutex" and write.
Another question arises of "concurrency" which can be handled different ways check out linux RCU (Read-Copy-Update) on similar lines.
First of all, What is the difference between mutex & semaphore.
- Aashish July 23, 2012Binary semaphore is also called MUTEX as per their values but their purposes are different..
Semaphore is used for signalling purpose. A thread waiting for a semaphore might be signalled by the other thread.
Mutex is used for Blocking purpose.
Mutex is used to provide synchronization on same block of code.
An ownership kind of thing is attached with a MUTEX. The lock is released by the object which has acquired it.
While semaphore is used to control the access to finite number of resources.
Since, here is only queue,
Hence, i feel that MUTEX would be a better choice.