I have a logical problem where I'm just not sure how to solve this programmatically.
Let's assume this situation:
I have e.g. 4 Threads running - doing all the (nearly) same stuff which depends on external processes (hardware in this case) - let us name these threads "A-Threads". And on the other hands, I have 1 to 20 (or more) other threads waiting for the results from one the first A-Threads (each of these second threads hands over some work to a particular A-Thread) - let us name these 'B-Threads'.
I could solve this easily with critical sections when I just have just 1 A-Thread. And I maybe can handle this with WaitForMultipleObjects when I have more than one A-Thread - sending a message out that THIS A-Thread has finished its work and has 'time' to do the next work for a B-Thread - BUT - and here comes my question on this:
I just want ONE of my B-Threads to take over the A-Thread that finished its work to do some more for this particular B-Thread. How can I do this? I mean, how can I get sure that just ONE B-Thread takes over an A-Thread to let him work?
Is this possible and how would I get sure that there is no B-Thread that is waiting infinite to get his hands on an A-Thread? Because each time a B-Thread dies, another B-Thread fires up and will wait for an free A-Thread.
Any help and code snippets are welcome!
Many thanks in advance!