I have a consumer producer script in ASP.NET. I developed the Producer class, the Consumer class, and the class for storing shared objects and those responsible for communication between the Producer and Consumer by calling him the Mediator . Since I run the execution path at startup (in the parent), and one thread calls Producer.Start() and the other thread calls Consumer.Start() , I need to pass the Mediator link to Producer and Consumer (via Constructor ). Mediator is a smart class that optimizes many things, such as the length of the internal queue, but for now considers it as a cyclical blocking queue. Producer places new objects in the Mediator until the queue is full, and then Producer blocks. Consumer removes objects from the Mediator until there is nothing in the queue. For signaling between threads, I implemented two methods in the Mediator class: Wait() and Pulse() . The code looks something like this:
Class Mediator { private object _locker = new object(); public void Wait() { lock(_locker) Monitor.Wait(_locker); } public void Pulse() { lock(_locker) Monitor.Pulse(_locker); } }
Inside the broker, I use this.Pulse() every time something is called or called, so the waiting threads will be signaled and continue to work.
But I was faced with deadlocks and because I never used such a design for signal flows, am I not sure if something is wrong with the design or am I doing something wrong elsewhere?
thanks
source share