views:

73

answers:

2

Is there a limit in the maximum number of mutexes per process/thread in a Asp.net application?

Just in case the target operating systems are: Windows XP Pro, server 2003/2008 and Windows 7 in the near future. Usually the website is deployed in an App Pool.

A: 

I'm going to go out on a limb here and venture the possibility that you're probably (not necessarily) doing something wrong.

Raymond Chen said it best but, if you're worried about the maximum number of mutexes, you're probably protecting your resources at too fine a granularity.

Certainly there will be a maximum number even if it's dictated by available memory rather than a constant. However, I can't see any valid situation in which you would need so many mutexes that you would hit a limit.

I'm not saying it's not possible since I have no idea what the architecture of your application is. But I would be very surprised if there wasn't a better way to do it.

Perhaps if you step back and tell us the "what I want" rather than the "how I did it", we could offer better advice.

paxdiablo
web farm and 1000s of user accessing the same resource (config file)
mas_oz2k1
A: 

The limit is essentially the same as the limit on the number of handles a process can have. It's quite a big number: 16,777,216. Of course, the real limit is much lower, and depends on how much non-paged pool you have available, which isn't that big.

If you're worried about the limit, there's something wrong with your program. Keep in mind that critical sections usually delay the creation of any kernel objects, which means you can have a large number of them if there are few contentions.

wj32
If you see the posted link, it mentions that mutexes in XP has a maximum of 20. the site is a web farm that access 5 config files.
mas_oz2k1
Uh, no. There's a simple way to disprove your claim: open up Process Explorer and view handles (including unnamed handles) for several different processes. The number of Mutant objects will add up to much, much more than 20.
wj32