9

The documentation for the .NET Semaphore class states that:

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

In this case, if I want a guaranteed order (either FIFO or LIFO), what are my options? Is this something that just isn't easily possible? Would I have to write my own Semaphore? I assume that would be pretty advanced?

Thanks,

Steve

Brian Knoblauch
  • 20,639
  • 15
  • 57
  • 92
Steve Whitfield
  • 1,981
  • 3
  • 21
  • 30

1 Answers1

6

See this:

The FifoSemaphore works exactly like a normal Semaphore but also guarantees that tokens are served out to acquirers in the order that they manage to acquire the internal lock. The usage of a FifoSemaphore is identical to a Semaphore.

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
  • 1
    CodePlex that hosted this library is going to shut down, so I made a (not-quite-good) copy of it at https://github.com/pvgoran/dcutilities-codeplex-archive . Maybe it will be useful to someone. – pvgoran Mar 02 '21 at 05:22
  • Link in answer is dead - *"Hmmm… can't reach this page | DNS_PROBE_FINISHED_NXDOMAIN"*. – Pang Aug 14 '23 at 02:29