473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

c# and critical sections

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
7 5702
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
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
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
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
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


"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
2
by: Xarky | last post by:
Hi, I am trying to learn Critical Sections. I have written a small program. Source code problem below. What the program is doing is disabling the CRTL-C signal in the critical section. My...
6
by: MPH Computers | last post by:
Hi I am looking for some help on Threading and Critical Sections I have a main thread that controls an event the event handler creates a new thread for carrying out the work because the...
13
by: Hendrik van Rooyen | last post by:
Hi, I would like to do the following as one atomic operation: 1) Append an item to a list 2) Set a Boolean indicator It would be almost like getting and holding the GIL, to prevent a...
5
by: =?Utf-8?B?VmFubmk=?= | last post by:
Hi, I have a component where I need to have thread-safe access to a list. Operations on the list are done in critical sections (lock (lockObject) { ... } ) in the usual way, to make sure that no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.