What is the consensus number for semaphores?

前端 未结 4 1589
灰色年华
灰色年华 2021-02-02 17:36

(I think that) the consensus number for a mutex is 2.

What is the consensus number for semaphores (like in pthread_sem_*)?

What is the consensus number for condi

4条回答
  •  耶瑟儿~
    2021-02-02 17:59

    The answer depends on the supported operations on the mutex or the semaphore. If only blocking locks are supported, the consensus number is 1. If a thread can try to lock the mutex without waiting, the consensus number is 2. That is because if there are two threads, both can try to lock the mutex, both can agree which one got it, so there is consensus. If the mutex can additionally determine, for any number of threads, which thread has locked it, then the consensus number is infinite. I think the situation for semaphores is similar. Mutexes are equivalent to semaphores with the counter 1. I don't think consensus can be reached just with larger counters, it still comes down to the same operations. Pthreads supports non-blocking locks but not queries, so there the answer would be 2.

    Signaling a condition variable does nothing if any threads are not waiting for it, so they have consensus number 1.

提交回复
热议问题