RE: CRITICAL_SECTION failure on CE6
- From: Michal <Michal@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Feb 2009 09:19:03 -0800
Hi,
I do not know about CE6.0 limits, but it sounds like you may be better off
doing the protection yourself, perhaps using low level interlocked
inc/dec/test&mod etc). Assuming the possibility to have a lock rejected is
low, it may benefit the performance as well. Problem may be the priority
inheritance (if you need it) and slower acquiring/releasing a lock after
contention etc. as you would need then to interact with the OS.
Michal
"Werner" wrote:
Hi,.
Run this code:
const int COUNT = 100000;
CRITICAL_SECTION cs[COUNT];
int Initialize()
{
int i = 0;
SetLastError(0);
for (i = 0; i < COUNT; ++i)
{
InitializeCriticalSection(&cs[i]);
if (cs[i].hCrit == NULL)
{
DWORD e = GetLastError();
printf("failed at %d with %d\n", i, e);
break;
}
}
return i;
}
int Enter()
{
int i = 0;
SetLastError(0);
for (i = 0; i < COUNT; ++i)
{
EnterCriticalSection(&cs[i]);
if (cs[i].hCrit == NULL)
{
DWORD e = GetLastError();
printf("failed at %d with %d\n", i, e);
break;
}
}
return i;
}
Initialize();
Enter();
It fails after 65533 attempts when run on CE6. It runs fine on CE5.
I found out that the problem is not the CRITICAL_SECTION itself, but the
amount of HANDLES in use (underlying a CS uses a HANDLE). The problem is that
you can't know whether you reached the limit or not (though you can see this
on the hCrit member of the CS, but this isn't official documented. I found
out this behaviour by looking in the kernel source code)
No error what so ever is generated when the CS is not valid. Only if you do
eg CreateEvent() afterwards GetLastError() will return 14 (ERROR_OUTOFMEMORY).
I didn't find any documentation on the maximum allowed HANDLEs/ process in
CE6? Am I correct that it is limited to 65536 in CE6?
Is there a way to correctly create more CRITICAL_SECTIONS? I need to protect
several 10000s objects fro multithread access and I don't like to use shared
CSs as it might influence performance in my realtime app. Not to speak for
possible deadlocks that I might introduce.
Werner
- References:
- CRITICAL_SECTION failure on CE6
- From: Werner
- CRITICAL_SECTION failure on CE6
- Prev by Date: Re: PM UserIdle State
- Next by Date: Re: Committed last page of the stack exception under CE6
- Previous by thread: CRITICAL_SECTION failure on CE6
- Next by thread: Re: CRITICAL_SECTION failure on CE6
- Index(es):
Relevant Pages
|