Do Mutexes Guarantee Ordering of Acquisition? Unlocking Thread Takes It Again While Others Are Still Waiting

Do mutexes guarantee ordering of acquisition? Unlocking thread takes it again while others are still waiting

Known problem. C++ mutexes are thin layer on top of OS-provided mutexes, and OS-provided mutexes are often not fair. They do not care for FIFO.

The other side of the same coin is that threads are usually not pre-empted until they run out of their time slice. As a result, thread A in this scenario was likely to continue to be executed, and got the mutex right away because of that.

Fiddler won't filter results in Windows 7

What's the exact version number of Fiddler that you're using? The current version is v2.3.2.6, so if you're not using that, please upgrade and see if that helps.

If that does not resolve the problem, please tell me what you see in the Process column in the session list for requests that are coming from your browser.

I'm running Fiddler as administrator in Windows 7 (otherwise it shows no results)

That suggests that your computer has the "Use Machine Proxy Settings only" group policy applied. This group policy causes IE to ignore the per-user proxy settings that Fiddler normally sets. Fiddler can only set the per-machine proxy settings when run as Administrator.

C++/BOOST: Does condition_variable::wait( ) / notify( ) ensure ordering of threads waiting?

No such guarantess are given by the standard, notify_one may wake any thread that is currently waiting (§30.5.1):

void notify_one() noexcept;
Effects: If any threads are blocked waiting for *this, unblocks one of those theads.

The only way to ensure that a specific thread reacts to the event is to wake all threads and then have some additional synchronization mechanism that sends all but the correct thread back to sleep.

This is a fundamental limitation due to the requirements that the platform has to fulfill: Usually condition variables are implemented in a way that the waiting threads are put into a suspended state and will not get scheduled by the system again until a notify occurs. A scheduler implementation is not required to provide the functionality for selecting a specific thread for waking up (and many actually don't).

So this part of the logic inevitably has to be handled by user code, which in turn means you have to wake up all threads to make it work, because this is the only way to ensure that the correct thread will get woken at all.

Does order of unlocking mutexes make a difference here?

I cannot for the life of me figure out how a deadlock could result from this though if the locks are always obtained in the same order wherever both are used.

In these circumstances, I don't think the order of unlocking the mutexes could be the cause of a deadlock.

Since pthread_mutex_unlock() doesn't block, both mutexes would always get unlocked regardless of the order of the two calls.

Note that if you attempt to acquire any locks between the two unlock calls, this can change the picture completely.



Related Topics



Leave a reply



Submit