How to replace at runtime WaitHandle that a thread should wait

I am wondering how to safely change at runtime EventWaitHandle what the thread should wait.

Suppose, for example, that there are two threads (A and C) that are synchronized through EventWaitHandles. A does its job cyclically, and C waits until it receives a notification from A that it can start doing its job (for example, using AutoResetEvent). Template - ACAC ...

Later, a new thread (B) starts (for example, according to the user’s action), and its task must be performed between two existing threads in this way: A executes its task, then signals B and after B finishes it with signal C Now the ABCABC .. pattern. .

So, before thread C was expecting an EventWaitHandle shared with A, and later there should be a safe mechanism that makes C wait for another EventWaitHandle shared by B. It seems to me that the tricky part replaces the EventWaitHandle used by C, since after of this, I should easily start B, which will use EventWaitHandle to wait for task A and EventWaitHandle to give a signal for task C. The mechanism should also ensure that thread B is safely turned off and return to the initial situation when only threads A and C are working.

Is there a safe way to accomplish this using EventWaitHandle? If not, any other suggestion will be appreciated.

0
source share
2 answers

A , C . A C , C , B, B .

, : . C , , , . , , , , .

0

- , ( ) . , , .

0

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


All Articles