Does anybody know if there's a limit to the amount of critical section objects you can have? (excluding memory limits of course)

I can't find any documentation that mentions it so I assume no. I was hoping maybe somebody here would know.

The things that lead me to believe there is no limit include the fact that the caller must provide the memory, and the fact that the critical section functions raise an exception instead of returning an error.

But I don't know exactly what goes on under the hood when a thread waits on a critical section, so I could be way off base.

Answers and comments appreciated.
Posted on 2003-05-08 21:27:25 by iblis
I have never personally used a critical section, but i have never heard of there being a limit for them either.

As for brhaviour, only one thread can access the section at a time. Any other threads get queued (in a suspended state) until it is their turn.
Posted on 2003-05-09 02:13:36 by sluggy
I understand how they work and what they're for.
What I meant by 'under the hood' was what the OS does when you call one of the critical section APIs. If I knew that I'd have a better idea of what to make of the limitations.

I guess I should just write a program that initializes a huge array of critical sections and see how many I can create before it raises an exception.
Posted on 2003-05-09 02:30:42 by iblis
What it all boils down to is whether a critical section uses a kernel object or not - perhaps Inside Windows 2000 or a similar book has some insight?
Posted on 2003-05-09 03:16:13 by f0dder
Jeffrey Richter says that critical sections only make kernal objects when there is a contention for reasources.
Posted on 2003-05-09 15:43:52 by Mecurius
This page and this page both say, "A critical section is not a kernel object."

And then this page says, " A critical section itself is a Kernel object."


What resources in particular are you referring to Mecurius? I thought two or more threads contending for resources was the whole point of critical sections in the first place. ;)
Posted on 2003-05-09 17:25:26 by iblis
A critical section is a structure, a user-mode syncronization tool. So it's not a kernel object.
In fact, kernel object are those that can be shared between process's, and all of them can have a name.

Where does Richter say that?
You use CS's only when you know for sure there will be contention. If not, why would you need them? You can just access the resource.

Posted on 2003-05-10 20:35:44 by GogetaSSJ4