How to connect signals to complex circuits in .NET?

For some parallel code, I want to connect a bunch of signals together, like a circuit. In .NET, we can do WaitAll or WaitAny in a signal set. I want to do something like this:

WaitAny ( WaitAll (c1, c2), WaitAll (c3, c4) ) ;

Unfortunately, the library does not support the compilation of these operations in more complex trees. My questions are: (1) Is there a way to do this in .NET? (2) Is there a library for this in any language?

[edit: Corey asked for more]

I want to create a messaging library. There may be 10K small parallel queues, some with messages. I want to receive a message from the queue and execute the handler assigned to the queue. However, I cannot capture the following message until the handler is executed (single-threaded for each queue). So I really want to wait in line (received the message?) And the code (finished with the previous message?) Before I jump out and execute the next element.

+3
source share
3 answers

, , , WaitAll ( WaitAll), WaitAny. -, . , , Post Your Answer; -)

ManualResetEvent _Group1Event = new ManualReset(false);
ManualResetEvent _Group2Event = new ManualReset(false);

void SomeThread()
{
    ...
    WaitHandle.WaitAny(_Group1Event, _Group2Event);
    ...
}

void Group1WatcherThread()
{
    ...
    if (WaitHandle.WaitAll(c1, c2))
    {
       _Group1Event.Set();
    }
    ...
}

void Group2WatcherThread()
{
    ...
    if (WaitHandle.WaitAll(c3, c4))
    {
       _Group2Event.Set();
    }
    ...
}

WaitAll/WaitAny, , .

+1

, .NET , . .

-1

Source: https://habr.com/ru/post/1734965/


All Articles