C++ exception influence real time behaviour of CE
- From: "migitsned" <migitsned@xxxxxxxxxxx>
- Date: 16 Nov 2006 04:03:06 -0800
Hi,
We have found a very strange behaviour of WinCE. When a low priority
thread is causing a simple C++ exception it may happen, that high
priority threads are not sheduled properly during that time. One can
simple reproduce this with the following example.
Create a high priority thread, that does nothing else than incrementing
a counter every 10 msecs. In your main application thread with priority
251 (default) insert a while loop that does nothing else then throwing
and catching C++ exceptions. Measure the time your while loop takes (e.
g. 20 secs) and then compare it with the counter difference between
start point of while loop and end of while loop. You will see that
there the counter is not showing enough increments.
In our example throw 50000 exceptions. That takes us about 20 secs. Our
printfs show ~20000 ticks in the output --> this is correct.
But the output of the counter difference of the high priority thread
shows only a value of ~1000.
In our opinion it should show the number of ticks / 10 (that would be
abour 2000).
Please note that we know that exceptions shouldn't be used in such a
way and we don't do it. But we have special case where we see that we
loose serial port data because C++ exceptions occur in an application,
we have no control of.
Here is our example code:
HANDLE hThread = INVALID_HANDLE_VALUE;
bool bStop = false;
volatile DWORD dwCounter = 0;
class SerExcept : public std::exception
{
public:
SerExcept()
{
}
};
DWORD CounterThread(LPVOID)
{
HANDLE hEvent = CreateEvent( NULL, FALSE, TRUE, NULL );
while (!bStop)
{
WaitForSingleObject( hEvent, 10 );
InterlockedIncrement( (LPLONG)&dwCounter );
}
ReleaseMutex( hEvent );
CloseHandle( hEvent );
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
hThread = CreateThread( NULL, 0, CounterThread, 0, 0, NULL );
printf( "Set Counter thread priority to 0\n");
CeSetThreadPriority( hThread, 0 );
printf( "Start count\n" );
DWORD dwStartTick = GetTickCount();
DWORD dwStartCounter = dwCounter;
for (int iCount = 0; iCount < 50000; ++iCount)
{
try
{
SerExcept tmpSerExcept;
throw tmpSerExcept;
}
catch( const SerExcept& e )
{
}
}
printf( "Duration: %d counts\n", dwCounter - dwStartCounter );
printf( "Duration: %d ticks\n", GetTickCount() - dwStartTick );
bStop = true;
printf( "waiting for CounterThread() to terminate" );
WaitForSingleObject( hThread, 10000 );
CloseHandle(hThread);
printf( "exit\n" );
return 0;
}
Thankx
Roman
.
- Follow-Ups:
- Re: C++ exception influence real time behaviour of CE
- From: Barry Bond [MS]
- Re: C++ exception influence real time behaviour of CE
- Prev by Date: Re: How to get USB / Ethernet (NIC) working on MS Windows CE 5.0 ?
- Next by Date: Re: hibernate in WinCE
- Previous by thread: SD Card driver loading
- Next by thread: Re: C++ exception influence real time behaviour of CE
- Index(es):
Relevant Pages
|
Loading