سؤال

I found on SO this question very similar, however does not exactly thoroughly answer my question. Does java.util.concurrent.Sempaphore; with the overloaded constructor which take also the fairness (boolean) parameter, guarantee FIFO for the threads waiting for acquiring? Thanks in advance.

هل كانت مفيدة؟

المحلول

It builds a queue of waiting threads to acquire the Semaphore. This makes it quite a bit slower, but permits will be given in the order the threads were added to the queue.

Note: due to the race conditions which can occur in multiple threads, you cannot say that the thread which attempts to acquire the Semaphore will be added to the queue first e.g. if it pauses between trying to acquire the Semaphore and being added to the queue.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top