473,756 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5729
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.co m

"Piotrek Stachowicz" <dy******@poczt a.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.c om> 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.co m>
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.co m

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> 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.co m>
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.c om> wrote in
message news:eK******** *****@TK2MSFTNG P09.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.co m

"Piotrek Stachowicz" <dy******@poczt a.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.co m
"Piotrek Stachowicz" <dy******@poczt a.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.c om> wrote in message news:eK******** *****@TK2MSFTNG P09.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.co m

"Piotrek Stachowicz" <dy******@poczt a.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******@poczt a.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_MEMOR Y 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******** ******@TK2MSFTN GP12.phx.gbl...


"Piotrek Stachowicz" <dy******@poczt a.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_MEMOR Y 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
4598
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 process starts is not especially important, but it must be complete within a small number of seconds. The operations I am performing do not take a long time (hundreds of milliseconds), but as each part of the process is complete, my worker thread...
2
4153
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 problem is that when in the Critical Section I press the CTRL-C signal more than once. As supposed nothing happens, but when critical section ends, should it give me all the CTRL-C signals pressed or just one (its giving me one)?
6
3264
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 work may not be completed before the event is triggered again I am trying to add critical sections round the producer & consumer parts of
13
1627
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 thread swap out between the two operations. - sort of the inverted function than for which the GIL
5
2814
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 other thread will modify the list while operations are running. However, I at the end of the critical section, I need to fire an OnChange type of event, publishing the changed list item as part of my custom EventArgs. I want to be certain that...
0
10014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.