04-11-2023 09:59 AM
Hi all,
I am trying to get a process in three parallel loops to only execute if a global variable ("pump in use") is not true (only 1 loop gets to use the resource, the other two have to wait). I start process 1, but I do not want process 2 or 3 to run until I stop process 1 and make the variable false. In my example, I start process 1, then 2. P2 starts running. Starting P3 runs P3, even though P1 has never been stopped. I'm sure its easy but I am not seeing it.
04-11-2023 10:07 AM
Process 2 or 3 reset the global to False, so the next attempt will be free to run ...
04-11-2023 11:26 AM - edited 04-11-2023 11:57 AM
If you want us to look at your attached code, you also need to include the global variable (currently missing!)
From the code it looks like you are a beginner and right now is a really good time to forget all bad habits and learn the right way to do things.
04-11-2023 11:44 AM - edited 04-11-2023 11:44 AM
04-11-2023 02:13 PM
Thank you for your reply.
This is sample code to illustrate my issue. I have simplified my issue to show only that which is causing me a problem. In reality, these are three large independent loops running multiple processes at once. Each station happens to share a common pump, which is why I need to let P1 finish with the pump before P2 tries to use it.
Thanks for your critique on my programming, do you have a suggestion that would allow me to inhibit P2 & P3 while P1 is running?
04-11-2023 04:24 PM
You have attached a global (P1 in use) that has nothing to do with your original post.
All you might need is a single global variable (or maybe an action engine) that is an integer (instead of a boolean) and indicates which process uses the pump (and "-1" for nobody). Each process can check if the pump is free, grab it by writing its process to it, and set it to -1 when it is done.
We don't really have sufficient details to give more specific advice. What exactly is a process doing if the pump is not available? Wait for the pump? Some other tasks that don't require the pump?
04-11-2023 05:05 PM
Thanks for the reply.
I have a tank based chemical dosing system that has three tanks. I have three pumps and three chemicals (and multiple routing valves). Each tank has to run its 5 steps in order, moving from one chemical or step to the next. (I am using a state machine for this). As an example, Tank 1 step 1 is to open some valves which route chemical 1 to tank 1, and start pump 1. All three systems have to be able to run at the same time but if Tank 1 is using pump 1, Tank 2 cannot start pump 1 until Tank 1 is done with it. So after they start T1, then T2, I need to keep T2 in it's while loop until the pump becomes available, hence the sample code with three while loops, constantly looking for some permissive to end the loop and start running.
I like the idea of the integer variable. So I would write a "2" to the variable if #2 grabs the pump, and "0" when it releases it? And the others would look for "0" to trigger use? What if 1 is running, 2 and 3 are triggered, each waiting for their loop to end? One should grab it before the other? That's what I was hoping the Global booleans would do, but they don't.
Thanks again for the help. Yes, I am fairly new.
04-11-2023 05:36 PM - edited 04-11-2023 05:55 PM
@Gort000 wrote:
One should grab it before the other? That's what I was hoping the Global booleans would do, but they don't.
That simply needs a conflict resolution, completely independent of the implementation.
Assuming more than one process is waiting for a resource, should they get served...
Once you know how it should be resolved, just program it! Right? That's why an action engine would be more functional than a dumb global. It could keep an array of reservations and release them to a certain process only if no lower numbered process is also waiting.