06-14-2010 03:37 PM
Hi
Recently, I made a software for 4 different items: A1,A2,A3,A4. Each item is having their own logging buttons and generating their own file names based on time. Similarly each item is also having 4 different formulas and timers. All of these tasks are supposed to be run in parallel. I created about 8 parallel loops and my software was working fine. Today I had to add serial read loop and I found out that serial read loop is not executing.
This serial read code works fine if I delete my rest of loops. So can anybody tell me me how should I handle multiple loops. I know serial read code is right,its some synchronization issue. Or tell me how I can avoid parallel loops.
Thanks
Solved! Go to Solution.
06-14-2010 03:51 PM
06-14-2010 04:51 PM
You might also have the problem of the other 8 loops consuming all of the processor resources too.
However, like he said with out the code it's hard to assist.
Jason
06-15-2010 12:27 PM
Hi
I have managed to find the loops which are effecting my serial communication. These are 5 loops marked in green. At the moment, you wont be able to run the code but still you will be able to point me in right direction.
06-15-2010 12:37 PM
You have a lot of loops running at full speed, with each one trying to hog all the CPU time. Put a delay in each loop. Use 10 mS as the delay value. If you must run as fast as possible, use 0 mS, but still put the delay even if it is 0 mS. This will give CPU time to all loops. The serial loop should execute normally if it gets some CPU time.
Actually, some of the loops (the ones waiting for user to press a button) can use a 100 mS delay without any noticible difference. This gives even more time for the serial loop to run.
06-15-2010 02:12 PM - edited 06-15-2010 02:20 PM
In the serial loop, you need to move the setup routine outside of the loop, because it is loop invariant code.
You really need to learn about using Queues or Notifiers to pass data between loops if you're going to tackle these multiple loop projects. Your local variables are out of hand - you're reading stale data, likely have race conditions. There's over 500 billion threads about this.
06-15-2010 02:43 PM
Thanks for your quick reply. I will try putting some delay of 10ms in each loop and will see whether it works or not.