Semaphore with priority

谁说我不能喝 提交于 2019-12-08 05:55:29

问题


I know about the Semaphore class in the System.Threading namespace, but I don't see if it allows waiting threads to have different priorities levels.

If two threads are waiting for an open slot, is there a way to allow the thread with the higher priority to have the first open slot available?


回答1:


From the MSDN documentantion on the Semaphore class

There is no guaranteed order, such as FIFO or LIFO, in which blocked threads enter the semaphore.

But take a look at these two projects which both supports priority for threads.

Smart Thread Pool

Thread-safe priority queue in C#



来源:https://stackoverflow.com/questions/3455761/semaphore-with-priority

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!