问题
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