I do not think how to implement it.
There is a workflow called N times at the same time and a dispatcher thread. Both contain some cycles.
Dispatcher Thread:
- Performs 1 iteration.
- Gives permission to workflows.
- Waiting for each of them to perform 1 iteration.
Workflow cycle:
- Waiting for permission from the dispatcher.
- Performs 1 iteration.
- Reports the completion of an iteration.
They said that it can be implemented using a semaphore, but I can’t figure out how. I just understood how it can be used to restrict access to a code fragment, but what about the case described above?
It is necessary to use streams.
PS: if someone is confused by the lack of a description of exiting the cycles, they are finite, simply, it does not matter here.
Upd: it seems that I did not quite understand. Threading methods look like this:
//поток-диспетчер static void ProtocolThread(object input) { //... do { //... //здесь он должен давать разрешение и ждать } while (!complited); return; } //рабочий поток (вызывается несколько таких параллельно) static void ThreadMethod(object input) { //... do { //здесь он должен ждать разрешение //... //здесь сообщить о завершении итерации (если это необходимо) } while (!complited); return; } Threads start like this:
ThreadPool.QueueUserWorkItem(new WaitCallback(ProtocolThread));
completedvariable without synchronization? Oh well. - VladD