Talk:cpp/named req/Mutex

single total order
The text states:
 * "All lock and unlock operations on a single mutex occur in a single total order"

What does this mean?

Does this mean, that if thread_0 locked the mutex; and then thread_1, thread_2, thread_3, etc. call lock on it in this order, will they obtain the lock on the mutex in this same order??

Thanks

Ajneu (talk) 06:50, 12 June 2016 (PDT)


 * no, that's not what the line refers to. It is saying the mutex acts as (and is often implemented by means of) an atomic memory location: it has its timeline, independent of any thread's timeline. I'll wikilink it to std. --Cubbi (talk) 09:29, 12 June 2016 (PDT)

Does this then mean, that the order of aquiring the mutex (and continuing code-execution), could be in a different order, than the order in which the threads were put to sleep???
 * Ok thanks.

Can I just protect by a mutex, or do I need some special code, where the thread "pulls an atomic ticket".
 * Just consider this as an example: I want to put events into a queue, in the exact order in which they occurred.


 * Here's an example with just a mutex. Will this keep the order???


 * Here's an example with pulling an atomic ticket and keeping appropriate order:


 * Which one does what I want (keep the order)? Is the "mutex" alone good enough, or do I need to "pull the atomic ticket"?


 * I'm finding it difficult to see clearly on this...


 * Ajneu (talk) 10:26, 12 June 2016 (PDT)


 * it may be more efficient to look at programming forums or Q&A websites than this discussion page. For example, here's the StackOverflow discussion of POSIX mutex wake order: http://stackoverflow.com/questions/14947191 (short answer: there isn't any, just as in C++, although POSIX makes an explicit mention of the current scheduling policy as the determining factor).


 * Thanks. Ajneu (talk) 11:24, 12 June 2016 (PDT)