c# and critical sections

  • Thread starter Thread starter Nicholas Paldino [.NET/C# MVP]
  • Start date Start date
N

Nicholas Paldino [.NET/C# MVP]

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.
 
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
 
Nicholas Paldino said:
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,

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.
 
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 said:
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]
- (e-mail address removed)

Piotrek Stachowicz said:
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
 
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]
- (e-mail address removed)


Piotrek Stachowicz said:
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

message news:[email protected]...
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]
- (e-mail address removed)

Piotrek Stachowicz said:
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
 
Piotrek Stachowicz said:
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.
 
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
 
Back
Top