Thread switching infinite loop

Hi,
My app has  multiple threads with different prio's.
All threads are guarded by 1 watchdog thread (looptime <1000ms).
The WD-Thread is guarded by a HW-watchdog.
If a thread hangs the Highest-Prio watchdog thread detects this, and calls a 
handler.
This behaviour is coverred by unit-testcases, so please assume that the code 
is correct.

To test this, I force a hang-situation by inserting : while(1);
My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
Also the debugger is not responding anymore, I need to powerdown the target.

I tried several variations :
While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
While(1) Sleep(0);  // ERROR , NO watchdog alarm !
While(1) Sleep(1);  // OK, watchdog alarm !
Sleep(2000); // OK Watchdog alarm ! (>1000ms)

My questions :
If one thread does while(1); , the others should still be scheduled, right ?
It appears that they are not, the watchdog never gets a change to trigger 
the alarm anymore in the error situations.
The Sleep(0) situation surprises me, there should be little difference 
between Sleep(0) and Sleep(1), just some performance difference caused by 
more thread-switching, right ?

Platform : CE6.0,  CM-X270 (PXA270)

Any tips or suggestions are welcome.


Kind Regards,
Rob.








0
Utf
2/9/2010 10:34:01 AM
windowsce.platbuilder 744 articles. 0 followers. Follow

25 Replies
1153 Views

Similar Articles

[PageSpeed] 21

See the following link ...
http://www.bluebytesoftware.com/blog/PermaLink,guid,1c013d42-c983-4102-9233-ca54b8f3d1a1.aspx

I read that "Sleep(0) only gives up the current thread's time-slice to a 
thread at equal priority and is ready to run. To force the scheduler to the 
next thread in the queue (regardless of priority) you have to force your 
thread into the queue (which Sleep(0) does not) which can be accomplished 
with Sleep(1)".
So it seems that to schedule a thread with different priority (like you 
watch dog thread that has a higher priority...I suppose), Sleep(1) is 
necessary because your while(1) thread is forced into the queue.


-- 
Paolo Patierno
Embedded Software Engineer


"Rob" wrote:

> Hi,
> My app has  multiple threads with different prio's.
> All threads are guarded by 1 watchdog thread (looptime <1000ms).
> The WD-Thread is guarded by a HW-watchdog.
> If a thread hangs the Highest-Prio watchdog thread detects this, and calls a 
> handler.
> This behaviour is coverred by unit-testcases, so please assume that the code 
> is correct.
> 
> To test this, I force a hang-situation by inserting : while(1);
> My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> Also the debugger is not responding anymore, I need to powerdown the target.
> 
> I tried several variations :
> While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> While(1) Sleep(1);  // OK, watchdog alarm !
> Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> 
> My questions :
> If one thread does while(1); , the others should still be scheduled, right ?
> It appears that they are not, the watchdog never gets a change to trigger 
> the alarm anymore in the error situations.
> The Sleep(0) situation surprises me, there should be little difference 
> between Sleep(0) and Sleep(1), just some performance difference caused by 
> more thread-switching, right ?
> 
> Platform : CE6.0,  CM-X270 (PXA270)
> 
> Any tips or suggestions are welcome.
> 
> 
> Kind Regards,
> Rob.
> 
> 
> 
> 
> 
> 
> 
> 
0
Utf
2/9/2010 11:10:01 AM
Hi,
Thanks for yur response.

Besides the sleep issue (this was just a try) , the scheduler should stop a 
thread when it's quantum has passed, even if it's hanging or doing sleep(0)  
? 
My code runs fine under XP, even with the hang-test.

So the question remains...

Kind Regards,
Rob
www.robtso.nl




 

"Paolo Patierno" wrote:

> See the following link ...
> http://www.bluebytesoftware.com/blog/PermaLink,guid,1c013d42-c983-4102-9233-ca54b8f3d1a1.aspx
> 
> I read that "Sleep(0) only gives up the current thread's time-slice to a 
> thread at equal priority and is ready to run. To force the scheduler to the 
> next thread in the queue (regardless of priority) you have to force your 
> thread into the queue (which Sleep(0) does not) which can be accomplished 
> with Sleep(1)".
> So it seems that to schedule a thread with different priority (like you 
> watch dog thread that has a higher priority...I suppose), Sleep(1) is 
> necessary because your while(1) thread is forced into the queue.
> 
> 
> -- 
> Paolo Patierno
> Embedded Software Engineer
> 
> 
> "Rob" wrote:
> 
> > Hi,
> > My app has  multiple threads with different prio's.
> > All threads are guarded by 1 watchdog thread (looptime <1000ms).
> > The WD-Thread is guarded by a HW-watchdog.
> > If a thread hangs the Highest-Prio watchdog thread detects this, and calls a 
> > handler.
> > This behaviour is coverred by unit-testcases, so please assume that the code 
> > is correct.
> > 
> > To test this, I force a hang-situation by inserting : while(1);
> > My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> > Also the debugger is not responding anymore, I need to powerdown the target.
> > 
> > I tried several variations :
> > While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> > While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> > While(1) Sleep(1);  // OK, watchdog alarm !
> > Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> > 
> > My questions :
> > If one thread does while(1); , the others should still be scheduled, right ?
> > It appears that they are not, the watchdog never gets a change to trigger 
> > the alarm anymore in the error situations.
> > The Sleep(0) situation surprises me, there should be little difference 
> > between Sleep(0) and Sleep(1), just some performance difference caused by 
> > more thread-switching, right ?
> > 
> > Platform : CE6.0,  CM-X270 (PXA270)
> > 
> > Any tips or suggestions are welcome.
> > 
> > 
> > Kind Regards,
> > Rob.
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
0
Utf
2/9/2010 11:18:02 AM
It seems that the scheduler stops the thread but the scheduler itsef then 
reschedules the same thread because there aren't other threads with same 
priority. To force schedule of thread with different priority,  the Sleep(0) 
doesn't work like notice on the following explanation I have posted before :

"Sleep(0) only gives up the current thread's time-slice to a 
thread at equal priority and is ready to run. To force the scheduler to the 
next thread in the queue (regardless of priority) you have to force your 
thread into the queue (which Sleep(0) does not) which can be accomplished 
with Sleep(1)"

It's a bad thing but can you try to set watch dog thread priority equal to 
the while(1) thread priority ? Just for testing...

-- 
Paolo Patierno
Embedded Software Engineer


"Rob" wrote:

> Hi,
> Thanks for yur response.
> 
> Besides the sleep issue (this was just a try) , the scheduler should stop a 
> thread when it's quantum has passed, even if it's hanging or doing sleep(0)  
> ? 
> My code runs fine under XP, even with the hang-test.
> 
> So the question remains...
> 
> Kind Regards,
> Rob
> www.robtso.nl
> 
> 
> 
> 
>  
> 
> "Paolo Patierno" wrote:
> 
> > See the following link ...
> > http://www.bluebytesoftware.com/blog/PermaLink,guid,1c013d42-c983-4102-9233-ca54b8f3d1a1.aspx
> > 
> > I read that "Sleep(0) only gives up the current thread's time-slice to a 
> > thread at equal priority and is ready to run. To force the scheduler to the 
> > next thread in the queue (regardless of priority) you have to force your 
> > thread into the queue (which Sleep(0) does not) which can be accomplished 
> > with Sleep(1)".
> > So it seems that to schedule a thread with different priority (like you 
> > watch dog thread that has a higher priority...I suppose), Sleep(1) is 
> > necessary because your while(1) thread is forced into the queue.
> > 
> > 
> > -- 
> > Paolo Patierno
> > Embedded Software Engineer
> > 
> > 
> > "Rob" wrote:
> > 
> > > Hi,
> > > My app has  multiple threads with different prio's.
> > > All threads are guarded by 1 watchdog thread (looptime <1000ms).
> > > The WD-Thread is guarded by a HW-watchdog.
> > > If a thread hangs the Highest-Prio watchdog thread detects this, and calls a 
> > > handler.
> > > This behaviour is coverred by unit-testcases, so please assume that the code 
> > > is correct.
> > > 
> > > To test this, I force a hang-situation by inserting : while(1);
> > > My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> > > Also the debugger is not responding anymore, I need to powerdown the target.
> > > 
> > > I tried several variations :
> > > While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> > > While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> > > While(1) Sleep(1);  // OK, watchdog alarm !
> > > Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> > > 
> > > My questions :
> > > If one thread does while(1); , the others should still be scheduled, right ?
> > > It appears that they are not, the watchdog never gets a change to trigger 
> > > the alarm anymore in the error situations.
> > > The Sleep(0) situation surprises me, there should be little difference 
> > > between Sleep(0) and Sleep(1), just some performance difference caused by 
> > > more thread-switching, right ?
> > > 
> > > Platform : CE6.0,  CM-X270 (PXA270)
> > > 
> > > Any tips or suggestions are welcome.
> > > 
> > > 
> > > Kind Regards,
> > > Rob.
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
0
Utf
2/9/2010 11:33:01 AM
Rob <__rob_AT_robtso_DOT_nl__> wrote:
> My app has  multiple threads with different prio's.
> All threads are guarded by 1 watchdog thread (looptime <1000ms).
> The WD-Thread is guarded by a HW-watchdog.
> If a thread hangs the Highest-Prio watchdog thread detects this, and calls
> a handler.
> This behaviour is coverred by unit-testcases, so please assume that the
> code is correct.

Unless you tell me what exactly that dog is watching and how, I won't share
your assumption. ;) Seriously, I wouldn't trust things to be that easily
testable and also assume faulty tests. The following description is
actually such a test for the watchdog that shows a shortcoming, or?

> To test this, I force a hang-situation by inserting : while(1);
> My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> Also the debugger is not responding anymore, I need to powerdown the
> target.

Irks. You could have bitten yourself here. With a "while(1);", no
lower-priority thread will ever run. Neither in your task nor in the whole
system. I don't think the remote debugger link has a high priority, as it
is fully okay if that data comes a bit late. The WD should run though,
provided it has higher priority. It could be that this test can't be
meaningfully done with a remote debugger attached.

> I tried several variations :
> While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> While(1) Sleep(1);  // OK, watchdog alarm !
> Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> 
> My questions :
> If one thread does while(1); , the others should still be
> scheduled, right?

Right. It will run out its timeslice and then be pre-empted.

> It appears that they are not, the watchdog never gets a change to 
> trigger the alarm anymore in the error situations.

I'm not 100% sure that works, as I have never encountered such a situation
(but seen some strangeness in CE's threads...) Generally though, CE
provides preemptive multitasking and multithreading, so unless that one
thread has higher priority than all others or holds a lock the others are
waiting for, other threads should run.

> The Sleep(0) situation surprises me, there should be little difference
> between Sleep(0) and Sleep(1), just some performance difference caused by
> more thread-switching, right ?

No. Sleep(0) will never give CPU time to threads with a lower priority. If
only lower-priority threads are ready, it will re-schedule the current
thread. Sleep(1) however can give control to a lower-priority thread.

Good luck!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

0
Ulrich
2/9/2010 11:35:12 AM
Thanks, I'll try that....

But if we forget about the Sleep(0) issue,
How can the while(1); behaviour be explained ?
The High-prio WD thread should always be scheduled right ?

Kind regards,
Rob.
www.robtso.nl





"Paolo Patierno" wrote:

> It seems that the scheduler stops the thread but the scheduler itsef then 
> reschedules the same thread because there aren't other threads with same 
> priority. To force schedule of thread with different priority,  the Sleep(0) 
> doesn't work like notice on the following explanation I have posted before :
> 
> "Sleep(0) only gives up the current thread's time-slice to a 
> thread at equal priority and is ready to run. To force the scheduler to the 
> next thread in the queue (regardless of priority) you have to force your 
> thread into the queue (which Sleep(0) does not) which can be accomplished 
> with Sleep(1)"
> 
> It's a bad thing but can you try to set watch dog thread priority equal to 
> the while(1) thread priority ? Just for testing...
> 
> -- 
> Paolo Patierno
> Embedded Software Engineer
> 
> 
> "Rob" wrote:
> 
> > Hi,
> > Thanks for yur response.
> > 
> > Besides the sleep issue (this was just a try) , the scheduler should stop a 
> > thread when it's quantum has passed, even if it's hanging or doing sleep(0)  
> > ? 
> > My code runs fine under XP, even with the hang-test.
> > 
> > So the question remains...
> > 
> > Kind Regards,
> > Rob
> > www.robtso.nl
> > 
> > 
> > 
> > 
> >  
> > 
> > "Paolo Patierno" wrote:
> > 
> > > See the following link ...
> > > http://www.bluebytesoftware.com/blog/PermaLink,guid,1c013d42-c983-4102-9233-ca54b8f3d1a1.aspx
> > > 
> > > I read that "Sleep(0) only gives up the current thread's time-slice to a 
> > > thread at equal priority and is ready to run. To force the scheduler to the 
> > > next thread in the queue (regardless of priority) you have to force your 
> > > thread into the queue (which Sleep(0) does not) which can be accomplished 
> > > with Sleep(1)".
> > > So it seems that to schedule a thread with different priority (like you 
> > > watch dog thread that has a higher priority...I suppose), Sleep(1) is 
> > > necessary because your while(1) thread is forced into the queue.
> > > 
> > > 
> > > -- 
> > > Paolo Patierno
> > > Embedded Software Engineer
> > > 
> > > 
> > > "Rob" wrote:
> > > 
> > > > Hi,
> > > > My app has  multiple threads with different prio's.
> > > > All threads are guarded by 1 watchdog thread (looptime <1000ms).
> > > > The WD-Thread is guarded by a HW-watchdog.
> > > > If a thread hangs the Highest-Prio watchdog thread detects this, and calls a 
> > > > handler.
> > > > This behaviour is coverred by unit-testcases, so please assume that the code 
> > > > is correct.
> > > > 
> > > > To test this, I force a hang-situation by inserting : while(1);
> > > > My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> > > > Also the debugger is not responding anymore, I need to powerdown the target.
> > > > 
> > > > I tried several variations :
> > > > While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> > > > While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> > > > While(1) Sleep(1);  // OK, watchdog alarm !
> > > > Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> > > > 
> > > > My questions :
> > > > If one thread does while(1); , the others should still be scheduled, right ?
> > > > It appears that they are not, the watchdog never gets a change to trigger 
> > > > the alarm anymore in the error situations.
> > > > The Sleep(0) situation surprises me, there should be little difference 
> > > > between Sleep(0) and Sleep(1), just some performance difference caused by 
> > > > more thread-switching, right ?
> > > > 
> > > > Platform : CE6.0,  CM-X270 (PXA270)
> > > > 
> > > > Any tips or suggestions are welcome.
> > > > 
> > > > 
> > > > Kind Regards,
> > > > Rob.
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
0
Utf
2/9/2010 11:54:01 AM
Everything in what you show us let think that the WD-thread can't get 
the CPU if the 'hung-thread' does not yield. Moreover, everything 
behaves like the 'hung-thread' has a 'better' (not to say 'higher' or 
numerically lower) priority than the WD-thread.

So, at this stage, you should post us some code and give some clues:
	- What are the priorities of your threads, including of course the 
WD-thread? How do you set those priorities?
	- How does the WD-thread determines that another thread is hanged?

Remi


Le 09/02/2010 11:34, Rob a �crit :
> Hi,
> My app has  multiple threads with different prio's.
> All threads are guarded by 1 watchdog thread (looptime<1000ms).
> The WD-Thread is guarded by a HW-watchdog.
> If a thread hangs the Highest-Prio watchdog thread detects this, and calls a
> handler.
> This behaviour is coverred by unit-testcases, so please assume that the code
> is correct.
>
> To test this, I force a hang-situation by inserting : while(1);
> My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> Also the debugger is not responding anymore, I need to powerdown the target.
>
> I tried several variations :
> While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> While(1) Sleep(1);  // OK, watchdog alarm !
> Sleep(2000); // OK Watchdog alarm ! (>1000ms)
>
> My questions :
> If one thread does while(1); , the others should still be scheduled, right ?
> It appears that they are not, the watchdog never gets a change to trigger
> the alarm anymore in the error situations.
> The Sleep(0) situation surprises me, there should be little difference
> between Sleep(0) and Sleep(1), just some performance difference caused by
> more thread-switching, right ?
>
> Platform : CE6.0,  CM-X270 (PXA270)
>
> Any tips or suggestions are welcome.
>
>
> Kind Regards,
> Rob.
>
>
>
>
>
>
>
>
0
R
2/9/2010 12:37:19 PM
Hi,
Agreed, it seems that way.

The WD detects hangs based on a timeout per thread (typically 1 sec).
I have added some traces in the check-func of the WD, and see the WD thread 
not running anymore after the other thread hangs.
The prio of the hanging thread is 248 (CE_THREAD_PRIO_256_TIME_CRITICAL)
The prio of the WD normally is 247 (CE_THREAD_PRIO_256_TIME_CRITICAL-1)
I tried setting it to 200, no differrence.
The prio's are set directly from the application.

Am I correct in expecting the WD thread should run under these conditions ? 
if so, could this be a scheduler bug ? 
can't imaging this to be the case in such a base-component.

Kind regards,
Rob 
www.robtso.nl




"R. de Gravelaine" wrote:

> Everything in what you show us let think that the WD-thread can't get 
> the CPU if the 'hung-thread' does not yield. Moreover, everything 
> behaves like the 'hung-thread' has a 'better' (not to say 'higher' or 
> numerically lower) priority than the WD-thread.
> 
> So, at this stage, you should post us some code and give some clues:
> 	- What are the priorities of your threads, including of course the 
> WD-thread? How do you set those priorities?
> 	- How does the WD-thread determines that another thread is hanged?
> 
> Remi
> 
> 
> Le 09/02/2010 11:34, Rob a écrit :
> > Hi,
> > My app has  multiple threads with different prio's.
> > All threads are guarded by 1 watchdog thread (looptime<1000ms).
> > The WD-Thread is guarded by a HW-watchdog.
> > If a thread hangs the Highest-Prio watchdog thread detects this, and calls a
> > handler.
> > This behaviour is coverred by unit-testcases, so please assume that the code
> > is correct.
> >
> > To test this, I force a hang-situation by inserting : while(1);
> > My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> > Also the debugger is not responding anymore, I need to powerdown the target.
> >
> > I tried several variations :
> > While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> > While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> > While(1) Sleep(1);  // OK, watchdog alarm !
> > Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> >
> > My questions :
> > If one thread does while(1); , the others should still be scheduled, right ?
> > It appears that they are not, the watchdog never gets a change to trigger
> > the alarm anymore in the error situations.
> > The Sleep(0) situation surprises me, there should be little difference
> > between Sleep(0) and Sleep(1), just some performance difference caused by
> > more thread-switching, right ?
> >
> > Platform : CE6.0,  CM-X270 (PXA270)
> >
> > Any tips or suggestions are welcome.
> >
> >
> > Kind Regards,
> > Rob.
> >
> >
> >
> >
> >
> >
> >
> >
> .
> 
0
Utf
2/9/2010 2:20:12 PM
It seems that Lowering the hanging thread prio does give the expected result.
This does not change the fact that the WD thread is (and has been) always 
higher-prio than the hanging one. So I cannot explain why that would make a 
diferrence....

Any idea's ?

Kind regards,
Rob.
www.robtso.nl





"Rob" wrote:

> Hi,
> Agreed, it seems that way.
> 
> The WD detects hangs based on a timeout per thread (typically 1 sec).
> I have added some traces in the check-func of the WD, and see the WD thread 
> not running anymore after the other thread hangs.
> The prio of the hanging thread is 248 (CE_THREAD_PRIO_256_TIME_CRITICAL)
> The prio of the WD normally is 247 (CE_THREAD_PRIO_256_TIME_CRITICAL-1)
> I tried setting it to 200, no differrence.
> The prio's are set directly from the application.
> 
> Am I correct in expecting the WD thread should run under these conditions ? 
> if so, could this be a scheduler bug ? 
> can't imaging this to be the case in such a base-component.
> 
> Kind regards,
> Rob 
> www.robtso.nl
> 
> 
> 
> 
> "R. de Gravelaine" wrote:
> 
> > Everything in what you show us let think that the WD-thread can't get 
> > the CPU if the 'hung-thread' does not yield. Moreover, everything 
> > behaves like the 'hung-thread' has a 'better' (not to say 'higher' or 
> > numerically lower) priority than the WD-thread.
> > 
> > So, at this stage, you should post us some code and give some clues:
> > 	- What are the priorities of your threads, including of course the 
> > WD-thread? How do you set those priorities?
> > 	- How does the WD-thread determines that another thread is hanged?
> > 
> > Remi
> > 
> > 
> > Le 09/02/2010 11:34, Rob a écrit :
> > > Hi,
> > > My app has  multiple threads with different prio's.
> > > All threads are guarded by 1 watchdog thread (looptime<1000ms).
> > > The WD-Thread is guarded by a HW-watchdog.
> > > If a thread hangs the Highest-Prio watchdog thread detects this, and calls a
> > > handler.
> > > This behaviour is coverred by unit-testcases, so please assume that the code
> > > is correct.
> > >
> > > To test this, I force a hang-situation by inserting : while(1);
> > > My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> > > Also the debugger is not responding anymore, I need to powerdown the target.
> > >
> > > I tried several variations :
> > > While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> > > While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> > > While(1) Sleep(1);  // OK, watchdog alarm !
> > > Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> > >
> > > My questions :
> > > If one thread does while(1); , the others should still be scheduled, right ?
> > > It appears that they are not, the watchdog never gets a change to trigger
> > > the alarm anymore in the error situations.
> > > The Sleep(0) situation surprises me, there should be little difference
> > > between Sleep(0) and Sleep(1), just some performance difference caused by
> > > more thread-switching, right ?
> > >
> > > Platform : CE6.0,  CM-X270 (PXA270)
> > >
> > > Any tips or suggestions are welcome.
> > >
> > >
> > > Kind Regards,
> > > Rob.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > .
> > 
0
Utf
2/9/2010 3:11:03 PM
Not sure but, although the way you do seems to be correct, it it were me 
I would have set the WD-thread priority to a very-very-low value 
(something like 10), using CeSetThreadPriority.

The point may be in the way "The WD detects hangs based on a timeout per 
thread". How do you accomplish this? Is there a chance that there is a 
priority inversion somewhere 
(http://msdn.microsoft.com/en-us/library/aa450594.aspx)?

Remi


Le 09/02/2010 16:11, Rob a �crit :
> It seems that Lowering the hanging thread prio does give the expected result.
> This does not change the fact that the WD thread is (and has been) always
> higher-prio than the hanging one. So I cannot explain why that would make a
> diferrence....
>
> Any idea's ?
>
> Kind regards,
> Rob.
> www.robtso.nl
>
>
>
>
>
> "Rob" wrote:
>
>> Hi,
>> Agreed, it seems that way.
>>
>> The WD detects hangs based on a timeout per thread (typically 1 sec).
>> I have added some traces in the check-func of the WD, and see the WD thread
>> not running anymore after the other thread hangs.
>> The prio of the hanging thread is 248 (CE_THREAD_PRIO_256_TIME_CRITICAL)
>> The prio of the WD normally is 247 (CE_THREAD_PRIO_256_TIME_CRITICAL-1)
>> I tried setting it to 200, no differrence.
>> The prio's are set directly from the application.
>>
>> Am I correct in expecting the WD thread should run under these conditions ?
>> if so, could this be a scheduler bug ?
>> can't imaging this to be the case in such a base-component.
>>
>> Kind regards,
>> Rob
>> www.robtso.nl
>>
>>
>>
>>
>> "R. de Gravelaine" wrote:
>>
>>> Everything in what you show us let think that the WD-thread can't get
>>> the CPU if the 'hung-thread' does not yield. Moreover, everything
>>> behaves like the 'hung-thread' has a 'better' (not to say 'higher' or
>>> numerically lower) priority than the WD-thread.
>>>
>>> So, at this stage, you should post us some code and give some clues:
>>> 	- What are the priorities of your threads, including of course the
>>> WD-thread? How do you set those priorities?
>>> 	- How does the WD-thread determines that another thread is hanged?
>>>
>>> Remi
>>>
>>>
>>> Le 09/02/2010 11:34, Rob a �crit :
>>>> Hi,
>>>> My app has  multiple threads with different prio's.
>>>> All threads are guarded by 1 watchdog thread (looptime<1000ms).
>>>> The WD-Thread is guarded by a HW-watchdog.
>>>> If a thread hangs the Highest-Prio watchdog thread detects this, and calls a
>>>> handler.
>>>> This behaviour is coverred by unit-testcases, so please assume that the code
>>>> is correct.
>>>>
>>>> To test this, I force a hang-situation by inserting : while(1);
>>>> My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
>>>> Also the debugger is not responding anymore, I need to powerdown the target.
>>>>
>>>> I tried several variations :
>>>> While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
>>>> While(1) Sleep(0);  // ERROR , NO watchdog alarm !
>>>> While(1) Sleep(1);  // OK, watchdog alarm !
>>>> Sleep(2000); // OK Watchdog alarm ! (>1000ms)
>>>>
>>>> My questions :
>>>> If one thread does while(1); , the others should still be scheduled, right ?
>>>> It appears that they are not, the watchdog never gets a change to trigger
>>>> the alarm anymore in the error situations.
>>>> The Sleep(0) situation surprises me, there should be little difference
>>>> between Sleep(0) and Sleep(1), just some performance difference caused by
>>>> more thread-switching, right ?
>>>>
>>>> Platform : CE6.0,  CM-X270 (PXA270)
>>>>
>>>> Any tips or suggestions are welcome.
>>>>
>>>>
>>>> Kind Regards,
>>>> Rob.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>> .
>>>
0
R
2/9/2010 3:29:41 PM
I think we really need to see how you're checking for a given thread to be OK 
or dead.  If the high-priority thread is *waiting* on something, priority 
inversion can cause the thread on which it is waiting to get its priority 
elevated (in this case, your infinite loop thread could be elevated to the 
same priority as your watchdog thread).  This seems like the most-likely 
cause to me.  

Windows CE scheduling is very, very unlike Windows XP, so many assumptions 
about how things work will be wrong for CE.

Paul T.

"Rob" wrote:

> It seems that Lowering the hanging thread prio does give the expected result.
> This does not change the fact that the WD thread is (and has been) always 
> higher-prio than the hanging one. So I cannot explain why that would make a 
> diferrence....
> 
> Any idea's ?
> 
> Kind regards,
> Rob.
> www.robtso.nl
> 
> 
> 
> 
> 
> "Rob" wrote:
> 
> > Hi,
> > Agreed, it seems that way.
> > 
> > The WD detects hangs based on a timeout per thread (typically 1 sec).
> > I have added some traces in the check-func of the WD, and see the WD thread 
> > not running anymore after the other thread hangs.
> > The prio of the hanging thread is 248 (CE_THREAD_PRIO_256_TIME_CRITICAL)
> > The prio of the WD normally is 247 (CE_THREAD_PRIO_256_TIME_CRITICAL-1)
> > I tried setting it to 200, no differrence.
> > The prio's are set directly from the application.
> > 
> > Am I correct in expecting the WD thread should run under these conditions ? 
> > if so, could this be a scheduler bug ? 
> > can't imaging this to be the case in such a base-component.
> > 
> > Kind regards,
> > Rob 
> > www.robtso.nl
> > 
> > 
> > 
> > 
> > "R. de Gravelaine" wrote:
> > 
> > > Everything in what you show us let think that the WD-thread can't get 
> > > the CPU if the 'hung-thread' does not yield. Moreover, everything 
> > > behaves like the 'hung-thread' has a 'better' (not to say 'higher' or 
> > > numerically lower) priority than the WD-thread.
> > > 
> > > So, at this stage, you should post us some code and give some clues:
> > > 	- What are the priorities of your threads, including of course the 
> > > WD-thread? How do you set those priorities?
> > > 	- How does the WD-thread determines that another thread is hanged?
> > > 
> > > Remi
> > > 
> > > 
> > > Le 09/02/2010 11:34, Rob a écrit :
> > > > Hi,
> > > > My app has  multiple threads with different prio's.
> > > > All threads are guarded by 1 watchdog thread (looptime<1000ms).
> > > > The WD-Thread is guarded by a HW-watchdog.
> > > > If a thread hangs the Highest-Prio watchdog thread detects this, and calls a
> > > > handler.
> > > > This behaviour is coverred by unit-testcases, so please assume that the code
> > > > is correct.
> > > >
> > > > To test this, I force a hang-situation by inserting : while(1);
> > > > My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> > > > Also the debugger is not responding anymore, I need to powerdown the target.
> > > >
> > > > I tried several variations :
> > > > While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> > > > While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> > > > While(1) Sleep(1);  // OK, watchdog alarm !
> > > > Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> > > >
> > > > My questions :
> > > > If one thread does while(1); , the others should still be scheduled, right ?
> > > > It appears that they are not, the watchdog never gets a change to trigger
> > > > the alarm anymore in the error situations.
> > > > The Sleep(0) situation surprises me, there should be little difference
> > > > between Sleep(0) and Sleep(1), just some performance difference caused by
> > > > more thread-switching, right ?
> > > >
> > > > Platform : CE6.0,  CM-X270 (PXA270)
> > > >
> > > > Any tips or suggestions are welcome.
> > > >
> > > >
> > > > Kind Regards,
> > > > Rob.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > .
> > > 
0
Utf
2/9/2010 4:10:01 PM
The WD-Client-Check thread uses no locks, so AFAIK no chance of inversion...

My last remark was too quick : I lowered the hanging thread to 
CE_THREAD_PRIO_256_HIGHEST and the WD is now 
CE_THREAD_PRIO_256_TIME_CRITICAL, but still not working...
I am still trying differrent values...

Kind regards,
Rob
www.robtso.nl


"R. de Gravelaine" wrote:

> Not sure but, although the way you do seems to be correct, it it were me 
> I would have set the WD-thread priority to a very-very-low value 
> (something like 10), using CeSetThreadPriority.
> 
> The point may be in the way "The WD detects hangs based on a timeout per 
> thread". How do you accomplish this? Is there a chance that there is a 
> priority inversion somewhere 
> (http://msdn.microsoft.com/en-us/library/aa450594.aspx)?
> 
> Remi
> 
> 
> Le 09/02/2010 16:11, Rob a écrit :
> > It seems that Lowering the hanging thread prio does give the expected result.
> > This does not change the fact that the WD thread is (and has been) always
> > higher-prio than the hanging one. So I cannot explain why that would make a
> > diferrence....
> >
> > Any idea's ?
> >
> > Kind regards,
> > Rob.
> > www.robtso.nl
> >
> >
> >
> >
> >
> > "Rob" wrote:
> >
> >> Hi,
> >> Agreed, it seems that way.
> >>
> >> The WD detects hangs based on a timeout per thread (typically 1 sec).
> >> I have added some traces in the check-func of the WD, and see the WD thread
> >> not running anymore after the other thread hangs.
> >> The prio of the hanging thread is 248 (CE_THREAD_PRIO_256_TIME_CRITICAL)
> >> The prio of the WD normally is 247 (CE_THREAD_PRIO_256_TIME_CRITICAL-1)
> >> I tried setting it to 200, no differrence.
> >> The prio's are set directly from the application.
> >>
> >> Am I correct in expecting the WD thread should run under these conditions ?
> >> if so, could this be a scheduler bug ?
> >> can't imaging this to be the case in such a base-component.
> >>
> >> Kind regards,
> >> Rob
> >> www.robtso.nl
> >>
> >>
> >>
> >>
> >> "R. de Gravelaine" wrote:
> >>
> >>> Everything in what you show us let think that the WD-thread can't get
> >>> the CPU if the 'hung-thread' does not yield. Moreover, everything
> >>> behaves like the 'hung-thread' has a 'better' (not to say 'higher' or
> >>> numerically lower) priority than the WD-thread.
> >>>
> >>> So, at this stage, you should post us some code and give some clues:
> >>> 	- What are the priorities of your threads, including of course the
> >>> WD-thread? How do you set those priorities?
> >>> 	- How does the WD-thread determines that another thread is hanged?
> >>>
> >>> Remi
> >>>
> >>>
> >>> Le 09/02/2010 11:34, Rob a écrit :
> >>>> Hi,
> >>>> My app has  multiple threads with different prio's.
> >>>> All threads are guarded by 1 watchdog thread (looptime<1000ms).
> >>>> The WD-Thread is guarded by a HW-watchdog.
> >>>> If a thread hangs the Highest-Prio watchdog thread detects this, and calls a
> >>>> handler.
> >>>> This behaviour is coverred by unit-testcases, so please assume that the code
> >>>> is correct.
> >>>>
> >>>> To test this, I force a hang-situation by inserting : while(1);
> >>>> My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> >>>> Also the debugger is not responding anymore, I need to powerdown the target.
> >>>>
> >>>> I tried several variations :
> >>>> While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> >>>> While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> >>>> While(1) Sleep(1);  // OK, watchdog alarm !
> >>>> Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> >>>>
> >>>> My questions :
> >>>> If one thread does while(1); , the others should still be scheduled, right ?
> >>>> It appears that they are not, the watchdog never gets a change to trigger
> >>>> the alarm anymore in the error situations.
> >>>> The Sleep(0) situation surprises me, there should be little difference
> >>>> between Sleep(0) and Sleep(1), just some performance difference caused by
> >>>> more thread-switching, right ?
> >>>>
> >>>> Platform : CE6.0,  CM-X270 (PXA270)
> >>>>
> >>>> Any tips or suggestions are welcome.
> >>>>
> >>>>
> >>>> Kind Regards,
> >>>> Rob.
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>> .
> >>>
> .
> 
0
Utf
2/9/2010 4:19:02 PM
The WD thread uses no locks.
I have already seen that the threadfunction when its called runs to the end.
(put some traces 1,2,3,4,5 throughout the function)
Then it sleeps a while at the end of the loop (giving control to others).
So it never stops halfway through the loop.
When the hang occurs, it is NOT called anymore at all.
So the method for determining thread-timeouts is not important here since it 
is never called (and when called uses no locks).

kind regards,
Rob.





"Paul G. Tobey [eMVP]" wrote:

> I think we really need to see how you're checking for a given thread to be OK 
> or dead.  If the high-priority thread is *waiting* on something, priority 
> inversion can cause the thread on which it is waiting to get its priority 
> elevated (in this case, your infinite loop thread could be elevated to the 
> same priority as your watchdog thread).  This seems like the most-likely 
> cause to me.  
> 
> Windows CE scheduling is very, very unlike Windows XP, so many assumptions 
> about how things work will be wrong for CE.
> 
> Paul T.
> 
> "Rob" wrote:
> 
> > It seems that Lowering the hanging thread prio does give the expected result.
> > This does not change the fact that the WD thread is (and has been) always 
> > higher-prio than the hanging one. So I cannot explain why that would make a 
> > diferrence....
> > 
> > Any idea's ?
> > 
> > Kind regards,
> > Rob.
> > www.robtso.nl
> > 
> > 
> > 
> > 
> > 
> > "Rob" wrote:
> > 
> > > Hi,
> > > Agreed, it seems that way.
> > > 
> > > The WD detects hangs based on a timeout per thread (typically 1 sec).
> > > I have added some traces in the check-func of the WD, and see the WD thread 
> > > not running anymore after the other thread hangs.
> > > The prio of the hanging thread is 248 (CE_THREAD_PRIO_256_TIME_CRITICAL)
> > > The prio of the WD normally is 247 (CE_THREAD_PRIO_256_TIME_CRITICAL-1)
> > > I tried setting it to 200, no differrence.
> > > The prio's are set directly from the application.
> > > 
> > > Am I correct in expecting the WD thread should run under these conditions ? 
> > > if so, could this be a scheduler bug ? 
> > > can't imaging this to be the case in such a base-component.
> > > 
> > > Kind regards,
> > > Rob 
> > > www.robtso.nl
> > > 
> > > 
> > > 
> > > 
> > > "R. de Gravelaine" wrote:
> > > 
> > > > Everything in what you show us let think that the WD-thread can't get 
> > > > the CPU if the 'hung-thread' does not yield. Moreover, everything 
> > > > behaves like the 'hung-thread' has a 'better' (not to say 'higher' or 
> > > > numerically lower) priority than the WD-thread.
> > > > 
> > > > So, at this stage, you should post us some code and give some clues:
> > > > 	- What are the priorities of your threads, including of course the 
> > > > WD-thread? How do you set those priorities?
> > > > 	- How does the WD-thread determines that another thread is hanged?
> > > > 
> > > > Remi
> > > > 
> > > > 
> > > > Le 09/02/2010 11:34, Rob a écrit :
> > > > > Hi,
> > > > > My app has  multiple threads with different prio's.
> > > > > All threads are guarded by 1 watchdog thread (looptime<1000ms).
> > > > > The WD-Thread is guarded by a HW-watchdog.
> > > > > If a thread hangs the Highest-Prio watchdog thread detects this, and calls a
> > > > > handler.
> > > > > This behaviour is coverred by unit-testcases, so please assume that the code
> > > > > is correct.
> > > > >
> > > > > To test this, I force a hang-situation by inserting : while(1);
> > > > > My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> > > > > Also the debugger is not responding anymore, I need to powerdown the target.
> > > > >
> > > > > I tried several variations :
> > > > > While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog alarm !
> > > > > While(1) Sleep(0);  // ERROR , NO watchdog alarm !
> > > > > While(1) Sleep(1);  // OK, watchdog alarm !
> > > > > Sleep(2000); // OK Watchdog alarm ! (>1000ms)
> > > > >
> > > > > My questions :
> > > > > If one thread does while(1); , the others should still be scheduled, right ?
> > > > > It appears that they are not, the watchdog never gets a change to trigger
> > > > > the alarm anymore in the error situations.
> > > > > The Sleep(0) situation surprises me, there should be little difference
> > > > > between Sleep(0) and Sleep(1), just some performance difference caused by
> > > > > more thread-switching, right ?
> > > > >
> > > > > Platform : CE6.0,  CM-X270 (PXA270)
> > > > >
> > > > > Any tips or suggestions are welcome.
> > > > >
> > > > >
> > > > > Kind Regards,
> > > > > Rob.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > .
> > > > 
0
Utf
2/9/2010 4:29:03 PM
You haven't told us enough.  How do you define High-prio?

-- 
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT Eurotech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

Eurotech Inc.
www.Eurotech.com

"Rob" <__rob_AT_robtso_DOT_nl__> wrote in message 
news:96F03125-4307-449F-808F-304D46789907@microsoft.com...
> Thanks, I'll try that....
>
> But if we forget about the Sleep(0) issue,
> How can the while(1); behaviour be explained ?
> The High-prio WD thread should always be scheduled right ?
>
> Kind regards,
> Rob.
> www.robtso.nl
>
>
>
>
>
> "Paolo Patierno" wrote:
>
>> It seems that the scheduler stops the thread but the scheduler itsef then
>> reschedules the same thread because there aren't other threads with same
>> priority. To force schedule of thread with different priority,  the 
>> Sleep(0)
>> doesn't work like notice on the following explanation I have posted 
>> before :
>>
>> "Sleep(0) only gives up the current thread's time-slice to a
>> thread at equal priority and is ready to run. To force the scheduler to 
>> the
>> next thread in the queue (regardless of priority) you have to force your
>> thread into the queue (which Sleep(0) does not) which can be accomplished
>> with Sleep(1)"
>>
>> It's a bad thing but can you try to set watch dog thread priority equal 
>> to
>> the while(1) thread priority ? Just for testing...
>>
>> -- 
>> Paolo Patierno
>> Embedded Software Engineer
>>
>>
>> "Rob" wrote:
>>
>> > Hi,
>> > Thanks for yur response.
>> >
>> > Besides the sleep issue (this was just a try) , the scheduler should 
>> > stop a
>> > thread when it's quantum has passed, even if it's hanging or doing 
>> > sleep(0)
>> > ?
>> > My code runs fine under XP, even with the hang-test.
>> >
>> > So the question remains...
>> >
>> > Kind Regards,
>> > Rob
>> > www.robtso.nl
>> >
>> >
>> >
>> >
>> >
>> >
>> > "Paolo Patierno" wrote:
>> >
>> > > See the following link ...
>> > > http://www.bluebytesoftware.com/blog/PermaLink,guid,1c013d42-c983-4102-9233-ca54b8f3d1a1.aspx
>> > >
>> > > I read that "Sleep(0) only gives up the current thread's time-slice 
>> > > to a
>> > > thread at equal priority and is ready to run. To force the scheduler 
>> > > to the
>> > > next thread in the queue (regardless of priority) you have to force 
>> > > your
>> > > thread into the queue (which Sleep(0) does not) which can be 
>> > > accomplished
>> > > with Sleep(1)".
>> > > So it seems that to schedule a thread with different priority (like 
>> > > you
>> > > watch dog thread that has a higher priority...I suppose), Sleep(1) is
>> > > necessary because your while(1) thread is forced into the queue.
>> > >
>> > >
>> > > -- 
>> > > Paolo Patierno
>> > > Embedded Software Engineer
>> > >
>> > >
>> > > "Rob" wrote:
>> > >
>> > > > Hi,
>> > > > My app has  multiple threads with different prio's.
>> > > > All threads are guarded by 1 watchdog thread (looptime <1000ms).
>> > > > The WD-Thread is guarded by a HW-watchdog.
>> > > > If a thread hangs the Highest-Prio watchdog thread detects this, 
>> > > > and calls a
>> > > > handler.
>> > > > This behaviour is coverred by unit-testcases, so please assume that 
>> > > > the code
>> > > > is correct.
>> > > >
>> > > > To test this, I force a hang-situation by inserting : while(1);
>> > > > My watchdog does not detect this ! ( the wd-thread never runs 
>> > > > anymore ?)
>> > > > Also the debugger is not responding anymore, I need to powerdown 
>> > > > the target.
>> > > >
>> > > > I tried several variations :
>> > > > While(1) OutputDebugMessag(L"Hanging...\r\n");  // OK, watchdog 
>> > > > alarm !
>> > > > While(1) Sleep(0);  // ERROR , NO watchdog alarm !
>> > > > While(1) Sleep(1);  // OK, watchdog alarm !
>> > > > Sleep(2000); // OK Watchdog alarm ! (>1000ms)
>> > > >
>> > > > My questions :
>> > > > If one thread does while(1); , the others should still be 
>> > > > scheduled, right ?
>> > > > It appears that they are not, the watchdog never gets a change to 
>> > > > trigger
>> > > > the alarm anymore in the error situations.
>> > > > The Sleep(0) situation surprises me, there should be little 
>> > > > difference
>> > > > between Sleep(0) and Sleep(1), just some performance difference 
>> > > > caused by
>> > > > more thread-switching, right ?
>> > > >
>> > > > Platform : CE6.0,  CM-X270 (PXA270)
>> > > >
>> > > > Any tips or suggestions are welcome.
>> > > >
>> > > >
>> > > > Kind Regards,
>> > > > Rob.
>> > > >
>> > > >
>> > > >
>> > > >
>> > > >
>> > > >
>> > > >
>> > > > 


0
Bruce
2/9/2010 5:43:06 PM
> The WD thread uses no locks.
> I have already seen that the threadfunction when its called runs to the end.
> (put some traces 1,2,3,4,5 throughout the function)
> Then it sleeps a while at the end of the loop (giving control to others).
> So it never stops halfway through the loop.
> When the hang occurs, it is NOT called anymore at all.

"called"?  It's just a loop in the thread, right?

while ( 1 )
{
    if ( <do some operation that is not a blocking operation to find thread 
OK> )
    {
        OutputDebugString( TEXT( "Watcher sleeping\r\n" ) );
    }
    else
    {
        <destroy the bad thread>
    }

    Sleep( x );
}

Meanwhile, in the other thread, you have:

while ( <keep-running> )
{
    <notify watchdog that we are running>

    while(1)
    {
        OutputDebugString( TEXT( "Bad thread sleeping\r\n" ) );

        Sleep(0);
    }
}

And what you see in the debug output, when not running with the kernel or 
other debugger involved is:

Watcher sleeping
Bad thread sleeping
Bad thread sleeping
Bad thread sleeping
Bad thread sleeping
Bad thread sleeping
....for a period longer than x in the code above...
Bad thread sleeping
Bad thread sleeping
Bad thread sleeping
Bad thread sleeping
Bad thread sleeping

Yes?  I guarantee that this doesn't happen on a correct platform running 
normally.  I don't suppose that you are doing something to the 1ms tick timer 
in your OAL that might change in this situation, causing the tick timer not 
to fire or to fire only after a long time?  That would screw the scheduler 
very nicely.

Paul T.

0
Utf
2/9/2010 8:52:01 PM
Hi,
Yes, thats basically what's going on...
the hanging (2nd) thread toggles its timeout somewhere after the loop....
If the hang is activated, this toggling stops.
I dont destroy any threads.

Only there are some strange things:
Your format would work OK !
If you would leave out the: 
{
OutputDebugString( TEXT( "Bad thread sleeping\r\n" ) ); 
Sleep(0); 
}
branch , and replace it by a single ; , you have my situation.
A trace or sleep(other than 0) inside that branch causes it to work as 
expected.
while(1); causes the problem.

Sleep(0) is another story (see link posted earlyer), but leave that out for 
now....
I am not doing anything to the tick timer.
I'm working on it further today...
If I find out the cause, I'll post it here.

Kind regards,
Rob
www.robtso.nl




"Paul G. Tobey [eMVP]" wrote:

> 
> > The WD thread uses no locks.
> > I have already seen that the threadfunction when its called runs to the end.
> > (put some traces 1,2,3,4,5 throughout the function)
> > Then it sleeps a while at the end of the loop (giving control to others).
> > So it never stops halfway through the loop.
> > When the hang occurs, it is NOT called anymore at all.
> 
> "called"?  It's just a loop in the thread, right?
> 
> while ( 1 )
> {
>     if ( <do some operation that is not a blocking operation to find thread 
> OK> )
>     {
>         OutputDebugString( TEXT( "Watcher sleeping\r\n" ) );
>     }
>     else
>     {
>         <destroy the bad thread>
>     }
> 
>     Sleep( x );
> }
> 
> Meanwhile, in the other thread, you have:
> 
> while ( <keep-running> )
> {
>     <notify watchdog that we are running>
> 
>     while(1)
>     {
>         OutputDebugString( TEXT( "Bad thread sleeping\r\n" ) );
> 
>         Sleep(0);
>     }
> }
> 
> And what you see in the debug output, when not running with the kernel or 
> other debugger involved is:
> 
> Watcher sleeping
> Bad thread sleeping
> Bad thread sleeping
> Bad thread sleeping
> Bad thread sleeping
> Bad thread sleeping
> ...for a period longer than x in the code above...
> Bad thread sleeping
> Bad thread sleeping
> Bad thread sleeping
> Bad thread sleeping
> Bad thread sleeping
> 
> Yes?  I guarantee that this doesn't happen on a correct platform running 
> normally.  I don't suppose that you are doing something to the 1ms tick timer 
> in your OAL that might change in this situation, causing the tick timer not 
> to fire or to fire only after a long time?  That would screw the scheduler 
> very nicely.
> 
> Paul T.
> 
0
Utf
2/10/2010 7:37:01 AM
Paolo Patierno wrote:
> See the following link ...
>http://www.bluebytesoftware.com/blog/PermaLink,guid,1c013d42-c983-4102-9233-ca54b8f3d1a1.aspx

Or http://msdn.microsoft.com/en-us/library/ms686307(VS.85).aspx, which is
the reference it gives.

> I read that "Sleep(0) only gives up the current thread's time-slice to a
> thread at equal priority and is ready to run.

I read that there and in the MSDN docs, but I can't believe that. I would
think that this is a typo, i.e. that it should read "at equal or greater
priority and is ready to run". Have you actually seen this behaviour
somewhere?

Uli
(slightly puzzled and undercoffeinated still...)

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

0
Ulrich
2/10/2010 8:22:53 AM
"Rob" <__rob_AT_robtso_DOT_nl__> wrote in message 
news:274813A8-7D9B-4E9D-ABA0-F85637372494@microsoft.com...
>    CeSetThreadPriority(ThreadHandle1,CE_THREAD_PRIO_256_HIGHEST);
>    CeSetThreadPriority(ThreadHandle2,CE_THREAD_PRIO_256_TIME_CRITICAL);

I would like to reproduce this. But my VS2005 doesnt find the defines 
CE_THREAD_PRIO_256_HIGHEST and CE_THREAD_PRIO_256_TIME_CRITICAL. Can you 
send the numeric values?

Regards,
Helge


0
Helge
2/10/2010 11:41:30 AM
They are in WinBase.h of my SDK
#define CE_THREAD_PRIO_256_TIME_CRITICAL    
PRIO_WIN32_TO_CE(THREAD_PRIORITY_TIME_CRITICAL)

Takes some digging through macros...
resulting in 248 for critical, and 247 for highest
actual value is not so important, just make sure WD thread has higher prio.

Kind regards,
Rob.



"Helge Kruse" wrote:

> 
> "Rob" <__rob_AT_robtso_DOT_nl__> wrote in message 
> news:274813A8-7D9B-4E9D-ABA0-F85637372494@microsoft.com...
> >    CeSetThreadPriority(ThreadHandle1,CE_THREAD_PRIO_256_HIGHEST);
> >    CeSetThreadPriority(ThreadHandle2,CE_THREAD_PRIO_256_TIME_CRITICAL);
> 
> I would like to reproduce this. But my VS2005 doesnt find the defines 
> CE_THREAD_PRIO_256_HIGHEST and CE_THREAD_PRIO_256_TIME_CRITICAL. Can you 
> send the numeric values?
> 
> Regards,
> Helge
> 
> 
> .
> 
0
Utf
2/10/2010 12:40:07 PM
We need to know when the thread is doing what in order to debug it, so you 
really want to have some form of debug logging of the state.  So you don't 
have a sleep(0) in there.  You're constantly running with no blocking calls.  
That's a bad design, of course.

Paul T.

"Rob" wrote:

> Hi,
> Yes, thats basically what's going on...
> the hanging (2nd) thread toggles its timeout somewhere after the loop....
> If the hang is activated, this toggling stops.
> I dont destroy any threads.
> 
> Only there are some strange things:
> Your format would work OK !
> If you would leave out the: 
> {
> OutputDebugString( TEXT( "Bad thread sleeping\r\n" ) ); 
> Sleep(0); 
> }
> branch , and replace it by a single ; , you have my situation.
> A trace or sleep(other than 0) inside that branch causes it to work as 
> expected.
> while(1); causes the problem.
> 
> Sleep(0) is another story (see link posted earlyer), but leave that out for 
> now....
> I am not doing anything to the tick timer.
> I'm working on it further today...
> If I find out the cause, I'll post it here.
> 
> Kind regards,
> Rob
> www.robtso.nl
> 
> 
> 
> 
> "Paul G. Tobey [eMVP]" wrote:
> 
> > 
> > > The WD thread uses no locks.
> > > I have already seen that the threadfunction when its called runs to the end.
> > > (put some traces 1,2,3,4,5 throughout the function)
> > > Then it sleeps a while at the end of the loop (giving control to others).
> > > So it never stops halfway through the loop.
> > > When the hang occurs, it is NOT called anymore at all.
> > 
> > "called"?  It's just a loop in the thread, right?
> > 
> > while ( 1 )
> > {
> >     if ( <do some operation that is not a blocking operation to find thread 
> > OK> )
> >     {
> >         OutputDebugString( TEXT( "Watcher sleeping\r\n" ) );
> >     }
> >     else
> >     {
> >         <destroy the bad thread>
> >     }
> > 
> >     Sleep( x );
> > }
> > 
> > Meanwhile, in the other thread, you have:
> > 
> > while ( <keep-running> )
> > {
> >     <notify watchdog that we are running>
> > 
> >     while(1)
> >     {
> >         OutputDebugString( TEXT( "Bad thread sleeping\r\n" ) );
> > 
> >         Sleep(0);
> >     }
> > }
> > 
> > And what you see in the debug output, when not running with the kernel or 
> > other debugger involved is:
> > 
> > Watcher sleeping
> > Bad thread sleeping
> > Bad thread sleeping
> > Bad thread sleeping
> > Bad thread sleeping
> > Bad thread sleeping
> > ...for a period longer than x in the code above...
> > Bad thread sleeping
> > Bad thread sleeping
> > Bad thread sleeping
> > Bad thread sleeping
> > Bad thread sleeping
> > 
> > Yes?  I guarantee that this doesn't happen on a correct platform running 
> > normally.  I don't suppose that you are doing something to the 1ms tick timer 
> > in your OAL that might change in this situation, causing the tick timer not 
> > to fire or to fire only after a long time?  That would screw the scheduler 
> > very nicely.
> > 
> > Paul T.
> > 
0
Utf
2/12/2010 5:19:01 PM
Never mind!  Your later posts make it clear what that code was about...

Paul T.

"Paul G. Tobey [eMVP]" wrote:

> We need to know when the thread is doing what in order to debug it, so you 
> really want to have some form of debug logging of the state.  So you don't 
> have a sleep(0) in there.  You're constantly running with no blocking calls.  
> That's a bad design, of course.
> 
> Paul T.
> 
> "Rob" wrote:
> 
> > Hi,
> > Yes, thats basically what's going on...
> > the hanging (2nd) thread toggles its timeout somewhere after the loop....
> > If the hang is activated, this toggling stops.
> > I dont destroy any threads.
> > 
> > Only there are some strange things:
> > Your format would work OK !
> > If you would leave out the: 
> > {
> > OutputDebugString( TEXT( "Bad thread sleeping\r\n" ) ); 
> > Sleep(0); 
> > }
> > branch , and replace it by a single ; , you have my situation.
> > A trace or sleep(other than 0) inside that branch causes it to work as 
> > expected.
> > while(1); causes the problem.
> > 
> > Sleep(0) is another story (see link posted earlyer), but leave that out for 
> > now....
> > I am not doing anything to the tick timer.
> > I'm working on it further today...
> > If I find out the cause, I'll post it here.
> > 
> > Kind regards,
> > Rob
> > www.robtso.nl
> > 
> > 
> > 
> > 
> > "Paul G. Tobey [eMVP]" wrote:
> > 
> > > 
> > > > The WD thread uses no locks.
> > > > I have already seen that the threadfunction when its called runs to the end.
> > > > (put some traces 1,2,3,4,5 throughout the function)
> > > > Then it sleeps a while at the end of the loop (giving control to others).
> > > > So it never stops halfway through the loop.
> > > > When the hang occurs, it is NOT called anymore at all.
> > > 
> > > "called"?  It's just a loop in the thread, right?
> > > 
> > > while ( 1 )
> > > {
> > >     if ( <do some operation that is not a blocking operation to find thread 
> > > OK> )
> > >     {
> > >         OutputDebugString( TEXT( "Watcher sleeping\r\n" ) );
> > >     }
> > >     else
> > >     {
> > >         <destroy the bad thread>
> > >     }
> > > 
> > >     Sleep( x );
> > > }
> > > 
> > > Meanwhile, in the other thread, you have:
> > > 
> > > while ( <keep-running> )
> > > {
> > >     <notify watchdog that we are running>
> > > 
> > >     while(1)
> > >     {
> > >         OutputDebugString( TEXT( "Bad thread sleeping\r\n" ) );
> > > 
> > >         Sleep(0);
> > >     }
> > > }
> > > 
> > > And what you see in the debug output, when not running with the kernel or 
> > > other debugger involved is:
> > > 
> > > Watcher sleeping
> > > Bad thread sleeping
> > > Bad thread sleeping
> > > Bad thread sleeping
> > > Bad thread sleeping
> > > Bad thread sleeping
> > > ...for a period longer than x in the code above...
> > > Bad thread sleeping
> > > Bad thread sleeping
> > > Bad thread sleeping
> > > Bad thread sleeping
> > > Bad thread sleeping
> > > 
> > > Yes?  I guarantee that this doesn't happen on a correct platform running 
> > > normally.  I don't suppose that you are doing something to the 1ms tick timer 
> > > in your OAL that might change in this situation, causing the tick timer not 
> > > to fire or to fire only after a long time?  That would screw the scheduler 
> > > very nicely.
> > > 
> > > Paul T.
> > > 
0
Utf
2/12/2010 9:50:01 PM
Ulrich,

Don't you think that threads that are "at greater priority and ready to 
run" are already running? If they have a better priority and if they are 
not sleeping, why should they not run before the thread that calls Sleep(0)?

Just to clarify things ;-)
Remi


Le 10/02/2010 09:22, Ulrich Eckhardt a �crit :
> Paolo Patierno wrote:
>> See the following link ...
>> http://www.bluebytesoftware.com/blog/PermaLink,guid,1c013d42-c983-4102-9233-ca54b8f3d1a1.aspx
>
> Or http://msdn.microsoft.com/en-us/library/ms686307(VS.85).aspx, which is
> the reference it gives.
>
>> I read that "Sleep(0) only gives up the current thread's time-slice to a
>> thread at equal priority and is ready to run.
>
> I read that there and in the MSDN docs, but I can't believe that. I would
> think that this is a typo, i.e. that it should read "at equal or greater
> priority and is ready to run". Have you actually seen this behaviour
> somewhere?
>
> Uli
> (slightly puzzled and undercoffeinated still...)
>
0
R
2/14/2010 6:30:57 PM
R. de Gravelaine wrote:
> Don't you think that threads that are "at greater priority and ready to
> run" are already running? If they have a better priority and if they are
> not sleeping, why should they not run before the thread that calls
> Sleep(0)?

Well, and what happens if they were sleeping? Will a Sleep(0) in a
low-priority thread check if a high-priority thread as slept enough and
then run the high-priority thread? According to the documentation, it
won't, and that is what really puzzles me. Even worse, if I believe the OP,
then both an endless loop and a Sleep(0) loop don't, and that would mean
that a low-priority thread that accidentally gets a timeslice can render
the whole system non-functional by entering an endless loop.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

0
Ulrich
2/15/2010 9:24:10 AM

Le 15/02/2010 10:24, Ulrich Eckhardt a �crit :
> R. de Gravelaine wrote:
>> Don't you think that threads that are "at greater priority and ready to
>> run" are already running? If they have a better priority and if they are
>> not sleeping, why should they not run before the thread that calls
>> Sleep(0)?
>
> Well, and what happens if they were sleeping? Will a Sleep(0) in a
> low-priority thread check if a high-priority thread as slept enough and
> then run the high-priority thread? According to the documentation, it
> won't, and that is what really puzzles me. Even worse, if I believe the OP,
> then both an endless loop and a Sleep(0) loop don't, and that would mean
> that a low-priority thread that accidentally gets a timeslice can render
> the whole system non-functional by entering an endless loop.
>
> Uli
>

To execute the Sleep(0) instruction, the low-priority thread (let's call 
it LPT) has to be running... So, the other threads in the system are 
either sleeping or pending at a same or lower priority as the LPT.

 From what I understand, calling Sleep(0) is just a matter of yielding 
the CPU to other threads pending at the same priority as the running 
thread, if any. Just a matter of speeding-up the timeslice processing of 
the scheduler.
I agree with you about the magic of the (now very silent) OP problem. As 
Paul (and I) stated, we need more information here to try to understand 
what really happens.

Remi
0
R
2/15/2010 10:06:00 AM
On Feb 9, 4:34=A0am, Rob <__rob_AT_robtso_DOT_nl__> wrote:
> Hi,
> My app has =A0multiple threads with different prio's.
> All threads are guarded by 1 watchdog thread (looptime <1000ms).
> The WD-Thread is guarded by a HW-watchdog.
> If a thread hangs the Highest-Prio watchdog thread detects this, and call=
s a
> handler.
> This behaviour is coverred by unit-testcases, so please assume that the c=
ode
> is correct.
>
> To test this, I force a hang-situation by inserting : while(1);
> My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> Also the debugger is not responding anymore, I need to powerdown the targ=
et.
>
> I tried several variations :
> While(1) OutputDebugMessag(L"Hanging...\r\n"); =A0// OK, watchdog alarm !
> While(1) Sleep(0); =A0// ERROR , NO watchdog alarm !
> While(1) Sleep(1); =A0// OK, watchdog alarm !
> Sleep(2000); // OK Watchdog alarm ! (>1000ms)
>
> My questions :
> If one thread does while(1); , the others should still be scheduled, righ=
t ?
> It appears that they are not, the watchdog never gets a change to trigger
> the alarm anymore in the error situations.
> The Sleep(0) situation surprises me, there should be little difference
> between Sleep(0) and Sleep(1), just some performance difference caused by
> more thread-switching, right ?
>
> Platform : CE6.0, =A0CM-X270 (PXA270)
>
> Any tips or suggestions are welcome.
>
> Kind Regards,
> Rob.

This is a weird coincidence, I just encountered the exact same problem
last week with our software watchdog process (we are not using a
hardware watchdog).

Our app is in C# (CF 3.5) on CE 6.0 R2.  We have multiple processes,
all with their threads at normal priority, and a watchdog process that
monitors them on a ~3 sec Windows.Forms.Timer.  One of the things we
want the watchdog to catch is if one of those processes gets stuck in
a loop or some other high CPU load condition.  Unfortunately, when
another process loads the CPU, the watchdog thread seemingly does not
get scheduled.  I cannot get this to work and have a hard time
understanding why the CE thread scheduler is not behaving as expected--
I thought it was pre-emptive?

I originally had the main watchdog process thread at 250.  If I create
a test process that spawns some threads at priority 251 and sits in a
while(1) loop, the watchdog thread seemingly never gets scheduled (if
it did, the system would reset).  I tried setting the watchdog thread
to 200, still didn't work.  I then used OpenNETCF to set all threads
in the watchdog process (UI thread, finalizer, etc.) to 200 and it
still doesn't work.  I also tried using a threading timer and just a
while loop with a 3 sec sleep with no luck.
0
Ben
2/17/2010 2:42:45 PM
As mentioned in the thread earlier, if it's locking up, that's because a 
higher-priority thread is not ready-to-run.  I would suggest that your 
threads are not set to the priorities you think they are, aren't doing what 
you think they are, or your watchdog thread is blocking on something.

Paul T.

"Ben Schoepke" <bschoepke@gmail.com> wrote in message 
news:360ac48c-7fb5-4461-ab64-c47609fa7130@k18g2000prf.googlegroups.com...
On Feb 9, 4:34 am, Rob <__rob_AT_robtso_DOT_nl__> wrote:
> Hi,
> My app has multiple threads with different prio's.
> All threads are guarded by 1 watchdog thread (looptime <1000ms).
> The WD-Thread is guarded by a HW-watchdog.
> If a thread hangs the Highest-Prio watchdog thread detects this, and calls 
> a
> handler.
> This behaviour is coverred by unit-testcases, so please assume that the 
> code
> is correct.
>
> To test this, I force a hang-situation by inserting : while(1);
> My watchdog does not detect this ! ( the wd-thread never runs anymore ?)
> Also the debugger is not responding anymore, I need to powerdown the 
> target.
>
> I tried several variations :
> While(1) OutputDebugMessag(L"Hanging...\r\n"); // OK, watchdog alarm !
> While(1) Sleep(0); // ERROR , NO watchdog alarm !
> While(1) Sleep(1); // OK, watchdog alarm !
> Sleep(2000); // OK Watchdog alarm ! (>1000ms)
>
> My questions :
> If one thread does while(1); , the others should still be scheduled, right 
> ?
> It appears that they are not, the watchdog never gets a change to trigger
> the alarm anymore in the error situations.
> The Sleep(0) situation surprises me, there should be little difference
> between Sleep(0) and Sleep(1), just some performance difference caused by
> more thread-switching, right ?
>
> Platform : CE6.0, CM-X270 (PXA270)
>
> Any tips or suggestions are welcome.
>
> Kind Regards,
> Rob.

This is a weird coincidence, I just encountered the exact same problem
last week with our software watchdog process (we are not using a
hardware watchdog).

Our app is in C# (CF 3.5) on CE 6.0 R2.  We have multiple processes,
all with their threads at normal priority, and a watchdog process that
monitors them on a ~3 sec Windows.Forms.Timer.  One of the things we
want the watchdog to catch is if one of those processes gets stuck in
a loop or some other high CPU load condition.  Unfortunately, when
another process loads the CPU, the watchdog thread seemingly does not
get scheduled.  I cannot get this to work and have a hard time
understanding why the CE thread scheduler is not behaving as expected--
I thought it was pre-emptive?

I originally had the main watchdog process thread at 250.  If I create
a test process that spawns some threads at priority 251 and sits in a
while(1) loop, the watchdog thread seemingly never gets scheduled (if
it did, the system would reset).  I tried setting the watchdog thread
to 200, still didn't work.  I then used OpenNETCF to set all threads
in the watchdog process (UI thread, finalizer, etc.) to 200 and it
still doesn't work.  I also tried using a threading timer and just a
while loop with a 3 sec sleep with no luck. 


0
Paul
2/21/2010 1:43:21 AM
Reply:

Similar Artilces:

Problem with blocking of main thread with other thread
I have a problem with blocking of main thread: My application contains an interpreter and I need to write a debugger for it. The mainframe creates a thread that is interpreting instructions. When I need to break execution of instruction thread, I use WaitForSingleObject(m_WaitEventHandle, INFINITE); in the interpreter thread. Everything works fine until the window is opened from the interpreter. Then the mainframe freezes. When I break execution in VC the call stack for interpreter thread shows: � NTDLL! � KERNEL32! � CDebugManager::CheckBreakpoints() � CInterpreterThread::Run() � _Afx...

Where is my thread?
I posted a question about "Search for a value in multi-dimensionla array" an hour ago; where did that go? On 5/17/2010 17:38, Rick wrote: > I posted a question about "Search for a value in multi-dimensionla array" an > hour ago; where did that go? If you mean the one beginning with "Seach", posted almost half an hour before this one, it is there. :) On 5/17/2010 11:51 AM, Jackie wrote: > On 5/17/2010 17:38, Rick wrote: >> I posted a question about "Search for a value in multi-dimensionla >> array" an >> hour ag...

Simple Thread
I have created a thread in my MFC Dialog based application, in the thread function i want to have access to a user interface control that is attached to the main dialog. How can I do it? Regards, Mystique Mystique wrote: > I have created a thread in my MFC Dialog based application, in the thread > function i want to have access to a user interface control that is attached > to the main dialog. > How can I do it? > > Regards, > Mystique > > Indirectly, by posting a message to the main thread asking it to update the control. http://www.mvps.org/vcfaq/mfc/12.ht...

Diaglog/Threading Data Exchange Question
Greetings, I have learned a lot from all of you, and I hope to over come my latest road block. I have a smal IRC Chat client I am making. I have a Dialog Box with Control and I use a worker thread for connecting to IRC - That Thread will update controls on the Dialog by sending PostMessages. Now my problem is in the ListBox Control that I have extended to do popup menu with various commands. I need to be able to read that controls methods from within the Thread. so I need to do this from within my IRC Socket thread: (code not exact - pseudo code) CListBoxEx myUsers; //Defined in my ...

Need Help with Busy Dialog Thread
my application would perform a task. I want to stop the user from using the application's GUI untill the the BG task is finished. At first using Modal Dlg did not do the trick as every one now (apart from me) the the CDialog::DoModal() function has to return some how. So, I made a bit of research on the net and found a trick to display the Dialog using CWinThread derived class without stoping the main app window for executing the background task as follows: (1) In your header file define a CWinThread-derived class... class CDialogThread : public CWinThread { DECLARE_DYNCREATE(CDial...

Switching panes with a split document
Sorry to repeat the question (I forgot to check "notify me of replies" before), but what is the keyboard shortcut for switching back and forth between the two panes of a split document? F6, Shift+F6. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Alamandrew" <Alamandrew@discussions.microsoft.com> wrote in message news:5D9EE352-E22E-4E0C-91A6-0BE40A672F6B@microsoft.com... > Sorry to repeat the question (I forgot to check "notify me of replies" > before), but what is the keybo...

Switching back to CP_ACP instead of CP_THREAD_ACP
Hi, MFC conversions between Unicode and non-Unicode pages are done now using CP_THREAD_ACP instead of CP_ACP. Is there a way to change back to CP_ACP? I tried defining _CONVERSION_DONT_USE_THREAD_LOCALE but it does not apply to MFC DLL. I do not want to re-compile the DLL and redistribute it. I tried changing the pointer g_pfnGetThreadACP (atlconv.h) to point to a routine returning CP_ACP. However, it seems my program contains a different variable g_pfnGetThreadACP than the one MFC uses. Maybe there's a way to link to MFC variable? From programming point of view, is there a way to...

Killing thread from outside thread in MFC App
Hi, Thanks to all those who offered advise on my last query. I successfully used the worker thread method to give control back to the dialog box whilst background processing was being carried out. The issue I have now is closing that thread externally. The method I've used to create the thread uses a volatile boolean variable. Whilever it is set to TRUE, the thread remains alive. However, when I set the variable to FALSE from the calling process (user wants to end processing), it has no effect. The thread continues to run. I thought that declaring the variable as 'volatile'...

To Thread or not to thread
I am using a CRecordset object to retrieve data from a remote server. The time to retrieve the data is highly variable because of network traffic etc etc etc and has varied from a few ms to almost a minute. Question: Is it a good practice to use a worker thread to handle the database exchange to avoid having my main thread block for long periods of time? I assume that I would let the exchange timeout and then check the return status and a global variable to determine if it should keep trying until it returned data ( might be null but that's ok). Ron H. Ron, While it may be a tin...

Anyone care to offer advice for my Client / Server threading model
I'm a bit of a sockets newbie and not too sure what the established ways of handling CAsyncSockets are. I need to handle two way comms between two or more handheld pcs and a server. WIth the server I've got: 1 Thread polling for new connections 1 Thread per client connection. The client thread is stuck in a loop called from CWinThread::InitInstance and sits and calls the CAsyncSocket::Receive function until something arrives. It uses peekmessage and postmessage in this loop to see if the app wants me to send anything to the client. This is working erratically though - peekmessage know...

Basic Looping
I have made a form that will enter customer data in a worksheet and calculate several things, including checking a date range and adding totals to a table of weekly totals for the month. The code I wrote works, but I am new to programming and do not know how to create a more logically structured program. Here is a portion of the code I've written; how do I use a loop to accomplish the same thing? --------------------- If aMonth = "1" Then If Week = "1" Then WeekTotalJan = 0 Range("K4").Sel...

multi-threaded control not destroyed on exiting the page?
I have created an ActiveX control (subclassing COleControl) which uses the afxRegFreeThreading model, and I have a small sample web page which inserts the control using an <object> tag. I noticed that when my page places the control inside the <head> tag, the control's destructor is called when my browser goes to a different page. But if the control is inside the <body> tag, the destructor is not called when I leave the page. The control's destructor is eventually called when I exit my browser, but I fear that my control is continuing to occupy system resources unt...

Threads in MFC
Hi to all... I've made a multithreaded Application (with MFC of course) and it works well on some PC, but in others PC's with the same OS (Win2000SP4) it throws "access Violation" immediatly just when a thread starts. (No matter which one... just the first). I've supposed it was some lib missing, and I've installed VC6... it didn't solve anything. any suggestion? I had a similar problem when I didn't realize I was trying to distribute a DEBUG version of the program. Otherwise, can you post a code snippet? On Mon, 19 Apr 2004 16:55:16 +0200, Nicola Bam...

Emergency! Switching to Office 2007!
I have a custom menu written in Excel 2003, and we are switching to Office 2007 next week possibly. What do I need to do to retain this menu? -- I am running on Office 2003, unless otherwise stated. Hi Orion, > I have a custom menu written in Excel 2003, and we are switching to Office > 2007 next week possibly. What do I need to do to retain this menu? Is it written in VBA? If so, it will show up on the addins tab of the 2007 ribbon. Regards, Jan Karel Pieterse Excel MVP http://www.jkp-ads.com Member of: Professional Office Developer Association www.proofficed...

MAD monitoring thread?
I have Exchange 2000 running on a Win2K Server. I have a trust to an NT4 domain with an Exchange 5.5 Server. Both are in the same site and my goal is to move the mailboxes and whatnot to the Exchange 2000 box. So far, just getting 2000 to operate has been a problem. It's installed and running but my MS Exchange Info Store and MTA stacks won't start in the services. If I reboot, they start, but stop within a few minutes. I have errors in my application log for MSExchangeSA that say, "The MAD monitoring thread was unable to read its configuration from the DS." I have MSEx...

A thread within a thread...
Hi, If i create a thread within a thread, something like... void threadA(void lparam ) { ... (HANDLE)_beginthread(ThreadB,0,someotherlparam); ... // do more work _endthread(); // done } My question is what happens to the thread i created, (threadB), if it is not finished? Is it safe, good?, to stop threadA without waiting for threadB. Many thanks Sims There is no concept of "a thread within a thread". All threads are within a process, and they are all peers of each other. DO NOT use _beginthread in an MFC program. This is asking for trouble. An...

why CStatic.m_hWnd not valid use realtime thread
Hi All I build an MFC app, and loadlibrary a dll which use high priority (realtime level ) threads for serial communication but after freelibrary the dll, some CStatic and CEdit objects not valid, their m_hWnd becomes to NULL How can I restore these CWnd objects? Is OS release them thanks, waiting online ...

threads #2
I have a server/client application that communicates using threads. The server class uses a while loop inside a thread to wait for new connections in accept state, like this: var a = new var( ); while( (server.Accept(connection)) ) { ...... ...... } I have declared a variable (var) right before this loop which uses memory. I want to free/delete this variable at the end of the while loop, but the control never reaches there. How can I make sure that this variable gets deleted before the server side exits? Thanks. Jessica Jessica Weiner wrote: > I have a server/client applicatio...

forms looping
Hi there I have created a form with a header and footer. The body of the form loops around when I use the scroll bar to go down. Is there a way to make it stop once it gets to the bottom of the body of the form once-- rather than starting at the top again. I think it does 3 loops. -- Thank-you! Ruth Right click on the form section and turn Force New Page to aftersection. "Ruth" wrote: > Hi there > > I have created a form with a header and footer. The body of the form loops > around when I use the scroll bar to go down. Is there a way to make it stop > o...

Destroy thread and Terminate thread
Hi, is there any difference between "Destroy thread and Terminate thread" regds vinay "Vinay" <v.sheel@mailcity.com> wrote in message news:uXR4ntHIEHA.2576@TK2MSFTNGP09.phx.gbl... > Hi, > is there any difference between > "Destroy thread and Terminate thread" > regds > > vinay > > A quote from the docs: "TerminateThread is a dangerous function that should only be used in the most extreme cases." destroyThread, on the other hand, deletes the thread object created by createThread. The thread should be terminated by some o...

Having some trouble after switching from IMO to CW
I'm trying to get our Outlook users converted from internet mail to corporate/workgroup mode, mainly to use an exchange server to share calendars. We're having several problems getting it to behave the way we'd like. The first problem is, we'd like have several mail accounts set up in order to be able to send mail as differenet addresses. In CW mode, I get the impression from some of the knowledge base articles that the only way to do this is to create separate profiles and have Outlook prompt you at startup. Is there any other way to do this? Thanks! No. Support for being...

Start background thread when a UI button is clicked, and Update UI button from background thread
I was asked these questions during a technical interview: 1) When the user clicks on a button on the form and that invokes a lot of heavy-duty calculations, what would you do? My answer: I would use "BeginInvoke" to start a background worker thread to do the heavy-duty calculations, in order to avoid blocking the main UI thread. Then he asked, "What does 'BeginInvoke' do"? I said it was a .NET pattern to start a background thread from a UI thread. Did I get it right? 2) Why can't you simply update a button on the UI thread from a background ...

Oulook Delay when switching between messages
I am running Office XP on a XP Pro workstation. When I look at messages or switch between folders in outlook I net a consistant delay between each message. I will click on the next message but in the preview window the old message displays. After about 2 seconds the next message appears. I don't think it is a hardware issue because I am runing a 2ghz machine with 1gb of memory. Can someone help this is gettng annoying. Thanks, Bri Conrad Pfleging just solved the same problem I was having.... here's what he told me to do and it worked!!! "WHAT VERSION? If 2002, go to...

What is the shortcut for switching between worksheets?
I would like to find out what is the shortcut for switching between worksheets in the same workbook Hi there. Using Ctrl + Page Down moves to the sheet to the right. If using Ctrl + Page Up, this will move to the sheet to the left. Hope this is of some help. Ellie "DJALik" wrote: > I would like to find out what is the shortcut for switching between > worksheets in the same workbook ...

q; loop through all open workbooks
Hello, How can I loop through all open workbooks and copy the first sheet in a new file in Excel macro. I am trying to collect sheets in different workbooks under one file. Hi Jim Ron de Bruin has lots of code for carrying out this type of operation on his site http://www.rondebruin.nl/copy2.htm -- Regards Roger Govier "JIM.H." <JIMH@discussions.microsoft.com> wrote in message news:C4D1919F-4FAC-47DB-8C5A-FD42C589B5EC@microsoft.com... > Hello, > How can I loop through all open workbooks and copy the first sheet in > a new > file in Excel macro. I am t...