Strange problem doing infinite while loop in EXE

I ran into an unusual issue on Windows CE:

Run 3 EXE

1) At first the exe does some work every 8 minutes if no exit event is specified. 2) The second exe does some work every 5 minutes unless an exit event is specified. 3) The third exe while loop is running, and during the loop it does some work at random times. This while loop continues until the exit event occurs.

This completion event is now a global event and can be signaled by any process.

Problem When I run First exe it works fine, Run the second exe it works fine, run the third exe it works fine

When I run all exes, only the third exe is executed, and no instructions are executed on the first and second.

As soon as the third exe finishes, the first and second runs start being processed. Could it be that the while loop in the third exe takes all cpu cycles? I haven't tried to put Sleep, but I think it might do some tricks. But the OS should give a processor to all processes ... Any thoughts ???

0


source to share


4 answers


Place the while loop in the third EXE to sleep each time through the loop and see what happens. Even if that doesn't fix this particular example, it is never good practice to poll with a while loop, and even using Sleep inside the loop is a poor substitute for a proper timer.



+2


source


I also read on MSDN that CE allows (fewer) 32 processes at a time. (However, context switches are lightning fast ...). Some of them are already occupied by system services.



+1


source


(Out of memory) Processes in Windows CE run to completion if there are no processes with a higher priority, or they start for their temporary chunk (100ms) if there are other processes with equal priority. I'm not sure if Windows CE gives a process with an active / foreground window a little priority (like Windows does) or not.

In your situation, the first two processes are hungry on CPU time, so they never start until the third process finishes. Some ways to solve this problem:

  • Make the third process wait / block on some multiprocessor primitives (mutex, semaphore, etc.) and a short timeout. Using WaitForMultipleObjects / WaitForSingleObject etc.
  • Make a third wait process, using a call to sleep every time the loop runs.
  • Boost the priority of other processes, so when they need to start, they will abort the third process and actually start. I would probably call the least frequently named process the highest priority of the three processes.

Another thing to check is that the third process does indeed complete its tasks on time and does not bind the CPU to do its job normally.

+1


source


Yes, I think this is not a good solution. I can try to use a timer and see the results.

0


source







All Articles