There is any limit on how many critical section i

2019-07-28 01:56发布

i have a Class that can be accessed on multiple thread.

To make sure i don't have simultaneous access i will use a CCriticalSection

I was wondering if i can just create a CCriticalSectionfor any copy of the object (i think i can have about 100-1000 this object in the program) or it will be best to create a static member CCriticalSection and use this for all the object?

4条回答
Evening l夕情丶
2楼-- · 2019-07-28 02:35

Surely there is a limit, but 1000 is perfectly fine. But in your case I believe static member is better.

Creating extra objects is the last thing you should do from the performance prospective.

查看更多
仙女界的扛把子
3楼-- · 2019-07-28 02:35

Windows has no limit on the number of sections you can create other than available memory (due to internal debug linkages, its consumes more than sizeof(CCriticalSection) or sizeof(CriticalSection).

查看更多
Evening l夕情丶
4楼-- · 2019-07-28 02:42

Prior to XP/Server 2003 you could run out of kernel objects for CRITICAL_SECTIONs (specifically the event used to arbitrate when there was contention on the CRITICAL_SECTION). For XP and beyond you're bounded as you are for many things, by your virtual address space.

查看更多
欢心
5楼-- · 2019-07-28 02:47

If your scope was only to "signal" why not use InterlockedExchange and Interlock... family functions?

查看更多
登录 后发表回答