Do mutexes guarantee ordering of acquisition?

前端 未结 6 1234
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 15:35

A coworker had an issue recently that boiled down to what we believe was the following sequence of events in a C++ application with two threads:

  • Thread A ho

6条回答
  •  悲&欢浪女
    2020-12-09 16:30

    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.

提交回复
热议问题