I have a suggestion for C#
I would like reader/writer locks to be built in to the language.
When you want to aquire a loct on an object o you write
lock(o)
{
...//critical region
}
I would like to be able to write:
readlock(o)
{
...//critical region that only reads shared data
}
Behind the scenes, the first time readlock(o) was called, the locking
mechanism on o would be upgraded to a reader/writer lock and any active,
queued or future locks on o acqired by using lock(o) would become writer
locks.
That way there would be no difference for the programmer between usind a
reader/write lock and a normal lock, all you would need to know would be
that if you want to read and write shared data you use lock(o) and if you
only want to read shared data you just use readlock(o).
It may be feasible to downgrade the reader/writer lock to a normal lock
again if only lock(o) has been used for a long time with no readlock(o)'s
beeing called.
Reader/writer locks are very common and this approach would not force the
programmer to choose between a normal lock or a reader/writer lock, they
would be the same. Furthermore with my suggestion there would be no need for
creating a reader/writer lock object and creating try finally blocks etc.
The syntax is much easier to use.
If this is not the right place to post my suggestion, where do I send my
suggestion?
Kind Regards,
Allan Ebdrup 20 2190
On May 31, 9:50 am, "Allan Ebdrup" <ebd...@noemail .noemailwrote:
I have a suggestion for C#
I would like reader/writer locks to be built in to the language.
I'd definitely disagree with that idea. I'd prefer locks not to be
part of the language at all - the "using" statement with appropriate
locking types is all that's required.
<snip>
Reader/writer locks are very common
I can't remember the last time I used one, and I've done plenty of
multi-threaded code. Normally you can release the lock sufficiently
quickly that it's more efficient to just use a "normal" lock than to
use the heavier ReaderWriterLoc k. There's going to be a slimmer RW-
lock in .NET 3.5, but even so, I wouldn't want it in the language.
Where possible, the language should (IMO) avoid having dependencies on
the framework. There are exceptions, but they should be tightly
controlled.
Furthermore with my suggestion there would be no need for
creating a reader/writer lock object and creating try finally blocks etc.
The syntax is much easier to use.
A "using" statement is very easy to use.
See http://pobox.com/~skeet/csharp/miscu...e/locking.html for an
example - it could easily be expanded to have methods which take out a
ReaderWriter lock, or to have different types which would do that
appropriately.
If this is not the right place to post my suggestion, where do I send my
suggestion?
connections.mic rosoft.com is the normal place for suggestions and bug
reports. It's a good idea to get peer review on newsgroups first
though, so the suggestion can be "tuned" before submission.
Jon
On May 31, 9:50 am, "Allan Ebdrup" <ebd...@noemail .noemailwrote:
Just thinking about this further:
<snip>
Behind the scenes, the first time readlock(o) was called, the locking
mechanism on o would be upgraded to a reader/writer lock and any active,
queued or future locks on o acqired by using lock(o) would become writer
locks.
How would you expect that to work? The C# compiler still has to
produce "normal" framework code - if this is just syntactic sugar,
could you write the current C# equivalent which would upgrade the lock
in one thread from a simple monitor lock to a reader/writer lock when
a read-only lock was required in a different thread?
Jon
It is certainly a valid place to *discuss* it, but "connect" is
probably better for a proposal - but this would need a lot more
work... for instance, there is a big difference between how
ReaderWriterLoc k and Monitor (=lock at the moment) work - Monitor uses
part of the targetted object, but ReaderWriterLoc k is itself an
object. The two would not be compatible at all.
Monitor tends to be significantly more lightweight, so a syntax change
for this to use a "write" ReaderWriterLoc k would be a huge change -
but that is the only way it could possibly be compatible when you
consider re-entrancy, sub methods etc. Likewise, this wouldn't support
Pulse etc.
In short - I can't see it being feasible, and in most cases I can't
see a reason to try. In most scenarios, Monitor is more than adequate.
In those scenarios where you really do want parallel concurrent
access, the existing ReaderWriterLoc k syntax works. I can't remember
the "who" or the exact quote, but a good rule of thumb is: if you want
to make a change like this, it had better be *much* better, otherwise
it isn't worth it. In this case, I'm not sure that it is.
IMHO
Marc
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
>I would like reader/writer locks to be built in to the language.
I'd definitely disagree with that idea. I'd prefer locks not to be
part of the language at all - the "using" statement with appropriate
locking types is all that's required.
Agreed 100%.
>Reader/writer locks are very common
I can't remember the last time I used one, and I've done plenty of
multi-threaded code.
Likewise, on both counts...
-- http://www.markrae.net
On May 31, 10:06 am, "Jon Skeet [C# MVP]" <s...@pobox.com wrote:
<snip>
connections.mic rosoft.com is the normal place for suggestions and bug
reports.
Oops - as Marc pointed out, it's connect.microso ft.com.
Jon
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
On May 31, 9:50 am, "Allan Ebdrup" <ebd...@noemail .noemailwrote:
>I have a suggestion for C# I would like reader/writer locks to be built in to the language.
I'd definitely disagree with that idea. I'd prefer locks not to be
part of the language at all - the "using" statement with appropriate
locking types is all that's required.
<snip>
>Reader/writer locks are very common
I can't remember the last time I used one, and I've done plenty of
multi-threaded code. Normally you can release the lock sufficiently
quickly that it's more efficient to just use a "normal" lock than to
use the heavier ReaderWriterLoc k. There's going to be a slimmer RW-
lock in .NET 3.5, but even so, I wouldn't want it in the language.
Where possible, the language should (IMO) avoid having dependencies on
the framework. There are exceptions, but they should be tightly
controlled.
I see what you mean, I do use reader/writer locks for caching data that is
read very often in somewhat heavy operations and very seldom written. I
still like the idea of not having to choose wether you use a normal lock or
a reader/writer lock, and just upgrading the locking mecanism if needed.
>Furthermore with my suggestion there would be no need for creating a reader/writer lock object and creating try finally blocks etc. The syntax is much easier to use.
A "using" statement is very easy to use.
See http://pobox.com/~skeet/csharp/miscu...e/locking.html for an
example - it could easily be expanded to have methods which take out a
ReaderWriter lock, or to have different types which would do that
appropriately.
good example. I'm not sure what mean by the last part. Do you mean that you
could make code that upgrades from a normal lock to a reader/writer lock?
Kind Regards,
Allan Ebdrup
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
On May 31, 9:50 am, "Allan Ebdrup" <ebd...@noemail .noemailwrote:
Just thinking about this further:
<snip>
>Behind the scenes, the first time readlock(o) was called, the locking mechanism on o would be upgraded to a reader/writer lock and any active, queued or future locks on o acqired by using lock(o) would become writer locks.
How would you expect that to work? The C# compiler still has to
produce "normal" framework code - if this is just syntactic sugar,
could you write the current C# equivalent which would upgrade the lock
in one thread from a simple monitor lock to a reader/writer lock when
a read-only lock was required in a different thread?
I'm pretty sure it could be done. But I don't have a solution in mind.
On May 31, 10:33 am, "Allan Ebdrup" <ebd...@noemail .noemailwrote:
I can't remember the last time I used one, and I've done plenty of
multi-threaded code. Normally you can release the lock sufficiently
quickly that it's more efficient to just use a "normal" lock than to
use the heavier ReaderWriterLoc k. There's going to be a slimmer RW-
lock in .NET 3.5, but even so, I wouldn't want it in the language.
Where possible, the language should (IMO) avoid having dependencies on
the framework. There are exceptions, but they should be tightly
controlled.
I see what you mean, I do use reader/writer locks for caching data that is
read very often in somewhat heavy operations and very seldom written.
But how long does fetching the data take anyway, and how much
concurrency do you expect? If it's quick, it could well be that using
a ReaderWriter lock is still more expensive than a plain exclusive
monitor lock.
I still like the idea of not having to choose wether you use a normal lock or
a reader/writer lock, and just upgrading the locking mecanism if needed.
It would be a nice idea if it were feasible - but I don't *think* it
is.
A "using" statement is very easy to use.
Seehttp://pobox.com/~skeet/csharp/miscutil/usage/locking.htmlfor an
example - it could easily be expanded to have methods which take out a
ReaderWriter lock, or to have different types which would do that
appropriately.
good example. I'm not sure what mean by the last part. Do you mean that
you could make code that upgrades from a normal lock to a reader/writer
lock?
I don't think it could upgrade an existing, held lock into a reader/
writer lock. With *very* carefully defined semantics it might be
possible to work something out, but I'm not entirely sure. I don't
think it's worth the extra work though, personally.
Jon
On May 31, 12:09 pm, "Jon Skeet [C# MVP]" <s...@pobox.com wrote:
On May 31, 9:50 am, "Allan Ebdrup" <ebd...@noemail .noemailwrote:
Just thinking about this further:
<snip>
Behind the scenes, the first time readlock(o) was called, the locking
mechanism on o would be upgraded to a reader/writer lock and any active,
queued or future locks on o acqired by using lock(o) would become writer
locks.
How would you expect that to work? The C# compiler still has to
produce "normal" framework code - if this is just syntactic sugar,
could you write the current C# equivalent which would upgrade the lock
in one thread from a simple monitor lock to a reader/writer lock when
a read-only lock was required in a different thread?
Jon
Jon,
I agree 100%.
Where possible, the language should (IMO) avoid having dependencies on
the framework. There are exceptions, but they should be tightly
controlled.
I would say that the language should try to avoid as much as it can
having dependencies of any kind :).
Moty This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Wellesz |
last post by:
Hello,
It would be great if there was an option to tell PHP to let the user
manage all the HTTP headers instead of sending what it thinks is good for
the programmer...
For example when you write:
header("Status: 200 OK");
header("Location: /my_internal_redirected_page.php");
|
by: John |
last post by:
Hi:
I'd like to implement a simple map, which is a 2-D plane with many
points, e.g., 100. The points are not evenly distributed, i.e., some
points may have two neighbor points; some may have 5 or 6 neighbor
points. Could anyone suggest me a data structure for it.
Thanks in advance.
John
|
by: Paulo Jan |
last post by:
Hi all:
Let's say I'm designing a database (Postgres 7.3) with a list of all
email accounts in a certain server:
CREATE TABLE emails (
clienteid INT4,
direccion VARCHAR(512) PRIMARY KEY,
login varchar(128) NOT NULL,
|
by: J.Marsch |
last post by:
I don't know whether this is the appropriate place to give product feedback,
but here goes:
I would love to see some kind of diagnostic to let me know when implicit
boxing has occurred.
We have had a few instances where one developer or another was working on
code, and did not realize that by passing their value type to a method that
accepted an object parameter (or in many cases, a delegate).
|
by: vinay |
last post by:
I have a scenario, need your suggestion..
Our clients are already using the forms authentication where we check the
User/Pwd from SQL svr Database. We also have some SETTINGS for the user saved
in the database(helps us to restrict the user access some things) .
We wanted to implement AD authentication for the same and also keep the
existing SQL SVr User DB.
My Q would be how to MAP the LDAP user to the SQL svr User, so we can get
| |
by: sandeep chandra |
last post by:
Hey guys, I am new to this group.. i never know wot s going on in this
group.. but wot made be brought here is cpp.. guys am currently a
part of onw reaserch ... am new to everything.. i can prog in c and
a bit in cpp.. to say ..am a fair programmer... there is a new
problem in my research work.. which if solved , gives me a gud tool
to develop my prog in a much better way.. lemme describe my prob...
i have a routine in...
|
by: Jedrzej Miadowicz |
last post by:
I recently (re)discovered data binding in Windows Forms thanks to its
advances in Visual Studio 2005. As I looked a little deeper, however, I
realize that it still suffers from an irksome tendency to stick a whole
bunch of literal strings in my code. Quite frankly, I consider them a
plague imposed on developers by the RAD designers that come with Visual
Studio. The problem with using literal strings to refer to controls, data
sources,...
|
by: John Salerno |
last post by:
I apologize for the slightly off-topic nature, but I thought I'd just
throw this out there for anyone working on text editors or IDEs with
auto-completion.
I think it should be a feature, when an item is selected for
auto-completion in a drop-down box, that pressing the spacebar (in
addition to tab or enter) will automatically finish the word and add a
space. This is how Microsoft's new IDEs for .NET work, and I found it
very helpful to...
|
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...
|
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...
|
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,...
| |
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |