Linux synchronization with FIFO waiting queue

后端 未结 3 849
别跟我提以往
别跟我提以往 2020-12-15 02:01

Are there locks in Linux where the waiting queue is FIFO? This seems like such an obvious thing, and yet I just discovered that pthread mutexes aren\'t FIFO, and semaphores

3条回答
  •  时光取名叫无心
    2020-12-15 02:28

    If you are asking what I think you are asking the short answer is no. Threads/processes are controlled by the OS scheduler. One random thread is going to get the lock, the others aren't. Well, potentially more than one if you are using a counting semaphore but that's probably not what you are asking.

    You might want to look at pthread_setschedparam but it's not going to get you where I suspect you want to go.

    You could probably write something but I suspect it will end up being inefficient and defeat using threads in the first place since you will just end up randomly yielding each thread until the one you want gets control.

    Chances are good you are just thinking about the problem in the wrong way. You might want to describe your goal and get better suggestions.

提交回复
热议问题