views:

299

answers:

4

I am facing strange issue on Windows CE:

Running 3 EXEs

1)First exe doing some work every 8 minutes unless exit event is signaled. 2)Second exe doing some work every 5 minutes unless exit event signaled. 3)Third exe while loop is running and in while loop it do some work at random times. This while loop continues until exit event signaled.

Now this exit event is global event and can be signaled by any process.

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

When I run all exes then only third exe runs and no instructions get executed in first and second.

As soon as third exe gets terminated first and second starts get processing. It that can be the case that while loop in third exe is taking all CPU cycles? I havn't tried putting Sleep but I think that can do some tricks. But OS should give CPU to all processes ... Any thoughts ???

+2  A: 

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

MusiGenesis
A: 

Yeah I think that is not good solution . I may try to use timer and see the results..

Alien01
+1  A: 

On the MSDN, I also read that CE allows for (less than) 32 processes simultaneously. (However, the context switches are lightning fast...). Some are already taken by system services.

xtofl
Interesting. I once took over a .NET CF app that was creating new processes inside a while loop. I knew that was super-bad, but this is some added info as to why.
MusiGenesis
+1  A: 

(From Memory) Processes in Windows CE run until completion if there are no higher priority processes running, or they run for their time slice (100ms) if there are other processes of equal priority running. I'm not sure if Windows CE gives the process with the active/foreground window a small priority boost (just like desktop Windows), or not.

In your situation the first two processes are starved of processor time so they never run until the third process exits. Some ways to solve this are:

  • Make the third process wait/block on some multi-process primitives (mutex, semaphore, etc) and a short timeout. Using WaitForMultipleObjects/WaitForSingleObject etc.
  • Make the third process wait using a call to Sleep every time around the processing loop.
  • Boost the priority of the other processes so when they need to run they will interrupt the third process and actually run. I would probably make the least often called process have the highest priority of the three processes.

The other thing to check is that the third process does actually complete its tasks in time, and does not peg the CPU trying to do its thing normally.

Daemin