By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

c# and critical sections

P: n/a
Hi,
I need to create the situation in my system, where no more critical
sections can be initialized (win2000Server). I thought about creating a
simple c# application and using the Monitor class. The problem is, that the
function doesn't seem tothrow any exception when it runs out of space. What
can I do about it?

Piotrek
Nov 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Piotrek,

Why do you want to limit the number of critical sections that are used?
It almost sounds like you want to use a semaphore. This will allow a
certain number of accesses to it, but when the number is depleted, it will
block. There is a managed representation of a semaphore, which is
coincidentally called, Semaphore.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Piotrek Stachowicz" <dy******@poczta.onet.pl> wrote in message
news:ce**********@news.onet.pl...
Hi,
I need to create the situation in my system, where no more critical
sections can be initialized (win2000Server). I thought about creating a
simple c# application and using the Monitor class. The problem is, that the function doesn't seem tothrow any exception when it runs out of space. What can I do about it?

Piotrek

Nov 16 '05 #2

P: n/a
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Why do you want to limit the number of critical sections that are used?
It almost sounds like you want to use a semaphore. This will allow a
certain number of accesses to it, but when the number is depleted, it will
block. There is a managed representation of a semaphore, which is
coincidentally called, Semaphore.


Not in 1.1 there isn't, as far as I know. It's fairly easy to build
one, of course. Given your comment, is there one in 2.0? (I must get
round to installing the Whidbey beta some time...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

P: n/a
Jon,

You are right, it is in 2.0. If a solution is needed for 1.1, then I
believe you could wrap the calls to the windows API by creating a Semaphore
class of one's own, and use that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Why do you want to limit the number of critical sections that are used? It almost sounds like you want to use a semaphore. This will allow a
certain number of accesses to it, but when the number is depleted, it will block. There is a managed representation of a semaphore, which is
coincidentally called, Semaphore.


Not in 1.1 there isn't, as far as I know. It's fairly easy to build
one, of course. Given your comment, is there one in 2.0? (I must get
round to installing the Whidbey beta some time...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

P: n/a
Hi,
I think I was misunderstood. I'd like to create a STATE OF THE SYSTEM
where there can be no more critical sections initialized. I need this, to
test other application, which uses critical sections very often, and I want
to test its behaviour when no critical section cannot be initialized.
In order to create such state of the system I'd like to run a c# app.
And here is the problem: How can I do this?!

Piotrek

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eK*************@TK2MSFTNGP09.phx.gbl...
Piotrek,

Why do you want to limit the number of critical sections that are used? It almost sounds like you want to use a semaphore. This will allow a
certain number of accesses to it, but when the number is depleted, it will
block. There is a managed representation of a semaphore, which is
coincidentally called, Semaphore.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Piotrek Stachowicz" <dy******@poczta.onet.pl> wrote in message
news:ce**********@news.onet.pl...
Hi,
I need to create the situation in my system, where no more critical
sections can be initialized (win2000Server). I thought about creating a
simple c# application and using the Monitor class. The problem is, that

the
function doesn't seem tothrow any exception when it runs out of space.

What
can I do about it?

Piotrek


Nov 16 '05 #5

P: n/a
Piotrek,

In this case, you really can't do it. There is no central management
for critical sections (which don't exist in .NET anyways, you use the
Monitor class).

You would have to hook into the CLR, and then you might be able to
determine when a lock is taking place, but to be honest, I doubt you have
this level of control.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Piotrek Stachowicz" <dy******@poczta.onet.pl> wrote in message
news:ce**********@news.onet.pl...
Hi,
I think I was misunderstood. I'd like to create a STATE OF THE SYSTEM
where there can be no more critical sections initialized. I need this, to
test other application, which uses critical sections very often, and I want to test its behaviour when no critical section cannot be initialized.
In order to create such state of the system I'd like to run a c# app.
And here is the problem: How can I do this?!

Piotrek

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:eK*************@TK2MSFTNGP09.phx.gbl...
Piotrek,

Why do you want to limit the number of critical sections that are

used?
It almost sounds like you want to use a semaphore. This will allow a
certain number of accesses to it, but when the number is depleted, it will block. There is a managed representation of a semaphore, which is
coincidentally called, Semaphore.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Piotrek Stachowicz" <dy******@poczta.onet.pl> wrote in message
news:ce**********@news.onet.pl...
Hi,
I need to create the situation in my system, where no more critical sections can be initialized (win2000Server). I thought about creating a simple c# application and using the Monitor class. The problem is,
that the
function doesn't seem tothrow any exception when it runs out of space.

What
can I do about it?

Piotrek



Nov 16 '05 #6

P: n/a


"Piotrek Stachowicz" <dy******@poczta.onet.pl> wrote in message
news:ce**********@news.onet.pl...
Hi,
I think I was misunderstood. I'd like to create a STATE OF THE SYSTEM
where there can be no more critical sections initialized. I need this, to
test other application, which uses critical sections very often, and I
want
to test its behaviour when no critical section cannot be initialized.
In order to create such state of the system I'd like to run a c# app.
And here is the problem: How can I do this?!

Piotrek

You can't do this. A critical section is an in-process allocated memory
struct, so the number is only restricted by available virtual memory , there
is no system wide limit you can set.
When memory becomes scarce a STATUS_NO_MEMORY exception will be thrown when
initializing the CS, so you should simply handle this exception in a SEH.

Willy.
Nov 16 '05 #7

P: n/a
Hello,
Ok. I get it, but is the same true for mutexes? I mean, is their number
somehow limited by system or is just a matter (virtual) memory).

Piotrek

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:eW**************@TK2MSFTNGP12.phx.gbl...


"Piotrek Stachowicz" <dy******@poczta.onet.pl> wrote in message
news:ce**********@news.onet.pl...
Hi,
I think I was misunderstood. I'd like to create a STATE OF THE SYSTEM
where there can be no more critical sections initialized. I need this, to test other application, which uses critical sections very often, and I
want
to test its behaviour when no critical section cannot be initialized.
In order to create such state of the system I'd like to run a c# app.
And here is the problem: How can I do this?!

Piotrek

You can't do this. A critical section is an in-process allocated memory
struct, so the number is only restricted by available virtual memory ,

there is no system wide limit you can set.
When memory becomes scarce a STATUS_NO_MEMORY exception will be thrown when initializing the CS, so you should simply handle this exception in a SEH.

Willy.

Nov 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.