LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why the interactivity of semaphore is better than mutual lock??? (https://www.linuxquestions.org/questions/linux-newbie-8/why-the-interactivity-of-semaphore-is-better-than-mutual-lock-866951/)

tgvlcw 03-07-2011 07:56 AM

Why the interactivity of semaphore is better than mutual lock???
 
Please look at the code:
Code:

for(i = 0; i < 100; i++) {
        mutex_lock();
        ...
        mutex_unlock();
}

If a process A into the critical region 100 times, at this time, process B also into the critical region, now the B will be sleep until the A execute 100 times loop.

If I use the semaphore instead of the mutex_lock, it will never happen, the B will get the semaphore when the A isn't execute 100 times loop.

Does this the mutex feature??

Can anybody tell me, why it is??

archtoad6 03-07-2011 09:23 AM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread should be closed because it is a duplicate of:
http://www.linuxquestions.org/questi...2/#post4281467

Pending closure of this threads by the mods assigned to this forum, please post all replies there.


tgvlcw,

Welcome to LQ. Hope you get the help you need here.
BTW, please review the LQ Rules & try not to cross post again. It's against the rules for a good reason -- it dilutes the discussion.
Thank you for your co-operation.


All times are GMT -5. The time now is 04:38 PM.