473,322 Members | 1,522 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,322 software developers and data experts.

Executing methods in atomic manner

7
i am learning the c#. i want to know how can i ensure that a method get executed in atomic manner.

I read about lock and [MethodImpl(MethodImplOptions.Synchronized)]....both prevents multiple threads from accessing a code concurrently.

Is this ensure the block get executed without thread switching...the thread from getting switched in middle of executing the block.


Expand|Select|Wrap|Line Numbers
  1. Class ClassCalc 
  2. {
  3.  
  4.     // implementation
  5.  
  6. }
  7.  
  8. class Update
  9. {
  10.    ClassCalc calc;
  11.  
  12.    public void UpdateValue()
  13.     {
  14.     if(calc.GetValue() > 0) // check whether the value of some 
  15.                                                //variable  in  calc is > 0 
  16.     {
  17.         //Do something
  18.  
  19.         calc.SetValue(somevalue); // Set the variable.
  20.     }
  21.     }
  22.  
  23. }
  24.  
  25. The SetValue and GetValue being public can be accessed by some other application.
  26. How can i ensure that no other thread update the variable in between GetValue() and SetValue() in the above code.
  27.  
  28.  
  29.  
Thanks
Jan 3 '08 #1
0 901

Sign in to post your reply or Sign up for a free account.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
8
by: Matthew Bell | last post by:
Hi, I've got a question about whether there are any issues with directly calling attributes and/or methods of a threaded class instance. I wonder if someone could give me some advice on this. ...
0
by: Brett C. | last post by:
My thesis, "Localized Type Inference of Atomic Types in Python", was successfully defended today for my MS in Computer Science at the California Polytechnic State University, San Luis Obispo. With...
42
by: Shayan | last post by:
Is there a boolean flag that can be set atomically without needing to wrap it in a mutex? This flag will be checked constantly by multiple threads so I don't really want to deal with the overhead...
14
by: Steven T. Hatton | last post by:
Can anyone recommend a good book on numerical methods that presents the subject using C++ in an ideal manner? -- "If our hypothesis is about anything and not about some one or more particular...
6
by: blackstreetcat | last post by:
consider this code : int i; //gobal var Thread1: i=some value; Thread2: if (i==2) dosomething(); else dosomethingelse();
3
by: Ole Nielsby | last post by:
I need to implement reference counting in a class hierarch, in a thread safe manner. (The classes are umanaged but I might want to compile them with the /clr option.) Some of the objects - atoms...
4
by: Mahesh S | last post by:
Hi I want to write a user defined function which does the following. 1. Take a string value as input parameter 2. Should execute a sql statement: select col1, col2, col3, col4 from table_name...
0
by: wugon.net | last post by:
Hi , Anyone know how to monitor db2 trigger activity ? We suffer some trigger issue today and we try to monitor trigger's behavior use event monitor and db2audit, but both tools can not get...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.