473,385 Members | 2,274 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,385 software developers and data experts.

Declaritive syncronization thoughts...

What if we had some kind on declarative synchronization where you could
declare, in declaration section, different lock sets for your invariant?
Something like:

public class MyClass
{
lock(sync1) // All three vars protected by same lock declaratively
(via internal object named sync1)..
{
private int counter1;
private int counter2;
private object obj;
}
lock(sync2) // These vars protected by a different lock and atomic
together.
{
private int someother;
private string desc;
}
private readonly string id = "123"; // no lock required.

public MyClass() {}

public string Name
{
get{ return name;}
set{ name = value;}
}
public int Counter1
{
get { return counter1; }
set { counter1 = value; }
}
}

Now you don't need lock blocks all over the place, but still get same
locking semantics when compiled. Also, I think this would help write better
code as you define your locking first based on your data (i.e. invariant
contract) and you can't forget to lock something and it reduces clutter and
number of lines you need to write. Maybe they could handle rw locks same
kind of way. Other ideas?

--
William Stacey, MVP
Nov 16 '05 #1
8 1292
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:OL**************@TK2MSFTNGP12.phx.gbl...
What if we had some kind on declarative synchronization where you could
declare, in declaration section, different lock sets for your invariant?
Something like:

<snip code>

Now you don't need lock blocks all over the place, but still get same
locking semantics when compiled. Also, I think this would help write better code as you define your locking first based on your data (i.e. invariant
contract) and you can't forget to lock something and it reduces clutter and number of lines you need to write. Maybe they could handle rw locks same
kind of way. Other ideas?


Isn't this kinda like the synchronized keyword in Java? Wouldn't you just
have a
new synchronized keyword for properties or maybe attributes?

[Lock(sync2)]
public int Counter1{ get; set; }

-c
Nov 16 '05 #2
Kinda. But this would be a bit different. That protects the whole method.
This would protect any access to any of the fields inside the declaration
regardless of where they are referenced inside the class. The attribute
itself is on target with what I was thinking however.

--
William Stacey, MVP

"Chad Myers" <cm****@N0.SP4M.austin.rr.com> wrote in message
news:Xt******************@fe2.texas.rr.com...
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:OL**************@TK2MSFTNGP12.phx.gbl...
What if we had some kind on declarative synchronization where you could
declare, in declaration section, different lock sets for your invariant?
Something like:

<snip code>

Now you don't need lock blocks all over the place, but still get same
locking semantics when compiled. Also, I think this would help write

better
code as you define your locking first based on your data (i.e. invariant
contract) and you can't forget to lock something and it reduces clutter

and
number of lines you need to write. Maybe they could handle rw locks same kind of way. Other ideas?


Isn't this kinda like the synchronized keyword in Java? Wouldn't you just
have a
new synchronized keyword for properties or maybe attributes?

[Lock(sync2)]
public int Counter1{ get; set; }

-c


Nov 16 '05 #3
<snip code>

Now you don't need lock blocks all over the place, but still get same
locking semantics when compiled. Also, I think this would help write
better
code as you define your locking first based on your data (i.e. invariant
contract) and you can't forget to lock something and it reduces clutter
and
number of lines you need to write. Maybe they could handle rw locks same
kind of way. Other ideas?


One problem that comes to mind is how do you lock for access over several
fields? Say you need to increment counter1 and counter2 without releasing
sync1?
Nov 16 '05 #4
Hi William,

Sorry for my ignorance. I haven't seen this before. Generally we use lock
statement to protect shared resources in code block. I don't know what's
the effect if we lock the declaration.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5
I was thinking about that issue as well. I think maybe their are two
approaches - the high road and low road.

High Road Solution:
Compiler and runtime together use the declarations and understand what needs
to be locked and how to write the code such that it does the right thing
based on meta data and some sophisticated logic (I would guess).

Low Road Solution:
The attributes verify during compile time that all said fields are accessed
in a locked context and flag compile errors if not. That alone would be a
big check I would think. It could also check that all vars in a "LockSet"
are accessed inside the same lock if they are read or written in the same
method. I ~think that all could be done just at compile time.

--
William Stacey, MVP

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:##**************@TK2MSFTNGP11.phx.gbl...
<snip code>

Now you don't need lock blocks all over the place, but still get same
locking semantics when compiled. Also, I think this would help write
better
code as you define your locking first based on your data (i.e. invariant
contract) and you can't forget to lock something and it reduces clutter
and
number of lines you need to write. Maybe they could handle rw locks same kind of way. Other ideas?


One problem that comes to mind is how do you lock for access over several
fields? Say you need to increment counter1 and counter2 without releasing
sync1?


Nov 16 '05 #6

"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:uf**************@TK2MSFTNGP15.phx.gbl...
I was thinking about that issue as well. I think maybe their are two
approaches - the high road and low road.

High Road Solution:
Compiler and runtime together use the declarations and understand what
needs
to be locked and how to write the code such that it does the right thing
based on meta data and some sophisticated logic (I would guess).

Low Road Solution:
The attributes verify during compile time that all said fields are
accessed
in a locked context and flag compile errors if not. That alone would be a
big check I would think. It could also check that all vars in a "LockSet"
are accessed inside the same lock if they are read or written in the same
method. I ~think that all could be done just at compile time.


Hrmm, I like the idea of declarativly defining lock sets. Even if it doesn't
automate anything it may well go a *long* way towards helping locking the
right things(even if it doesn't help much with lock acquisition order, ;).
Just being able to force locked(or interlocked) access may be a big boon.

I don't know how to do it, I certaily don't like attributes(IMHO, if a
feature *has* to use attributes, the feature is bad). Dreaming up syntax
would be the difficult part...
Nov 16 '05 #7
Kevin Yu [MSFT] <v-****@online.microsoft.com> wrote:
Sorry for my ignorance. I haven't seen this before. Generally we use lock
statement to protect shared resources in code block. I don't know what's
the effect if we lock the declaration.


It's a feature suggestion - it clearly doesn't compile at the moment.

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

Hi William,

If you have good suggestions that will make our future products better,
please feel free to send emails to ms****@microsoft.com directly. Your
suggestions will be highly appreciated. Thank you!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Stephen Horne | last post by:
Some more looping thoughts - this time on integer for loops... There may be some hint towards PEP284 (integer for loops) in a review of ideas from other languages, but I'm damned if i can figure...
39
by: Marco Aschwanden | last post by:
Hi I don't have to talk about the beauty of Python and its clear and readable syntax... but there are a few things that striked me while learning Python. I have collected those thoughts. I am...
1
by: Steve | last post by:
I'm still a database newbie so I would like to solicit thoughts about the smartest way to do something in sqlserver. My company has a web application that we customize for each client. We can...
4
by: Rajan | last post by:
Hi All C++ Experts Can anybody share some of your thoughts in Member Function Templates implementation.Can you also give some example on it Best Regards Raj
2
by: Ian | last post by:
Hi there, I wanted to get anybodys thoughts on using the following... <script src="http://test.com/myscript.js"></script> for including functions etc in the html page, of course I could...
5
by: Prabu Subroto | last post by:
Dear my friends... I am using SuSE Linux 9.1 and postgres. I am a beginner in postgres, usually I use MySQL. I have 3 tables : appointment, appointment0 and appointment1. the fields of...
35
by: Justin Weinberg | last post by:
My thoughts on this.... http://msdn.microsoft.com/vbasic/Future/default.aspx?pull=/library/en-us/dnvs05/html/vb9overview.asp My thoughts: 1. Regarding Implicit types, I don't use type...
2
Stang02GT
by: Stang02GT | last post by:
Hello, I would just like to get your thoughts/ideas/suggestions on how I should go about createing a VERY SIMPLE purchasing system. A friend has asked me help him develop a simple purchasing...
1
Stang02GT
by: Stang02GT | last post by:
Hello, I'm looking for your thoughts, ideas, and suggestions on this situation. I have recently been given the task to "fix" a menu within the companies intranet site. The current menu...
0
by: grazzy.cool | last post by:
"Change your language and you change your thoughts." Learn English and free download Grammar & dictionary. Just click the website and share ur thoughts…. "Language shapes the way we think, and...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.