The apparent solution could be simple. In your FIFO, store not just threads but give each thread its separate instance of
System.Threading.EventWaitHandle
,
System.Threading.Monitor
, instead of a thread instance, keep in your FIFO the record composing this instance with the
EventWaitHandle
or
Monitor
instance, and throttle each thread separately.
This is the solution. But does it makes sense? I doubt it. It looks like you whole approach may make little to no sense.
This is like having a number of thread, but without parallel operation. It may happen when you allow one non-waiting thread at a time. Why defeating the purpose of threading then?
But I was thinking of a plan
To dye one's whiskers green,
And always use so large a fan
That it could not be seen.
You can have the same thing by queuing tasks instead of threads. For example, you can queue delegate instances in a
blocking queue. For further explanation, please see my article:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[
^].
—SA