PC Review


Reply
Thread Tools Rate Thread

Atomic operations

 
 
Armin Zingler
Guest
Posts: n/a
 
      29th Oct 2009
Hi,

is there a documentation out there that tells me which operations are atomic?

I currently have to know if increasing a System.Decimal value is an atomic operation. I guess it is
not. The value is increased in one thread and read from another thread. I think I have to use a
lock. Right?

--
Armin
 
Reply With Quote
 
 
 
 
Peter Duniho
Guest
Posts: n/a
 
      29th Oct 2009
Armin Zingler wrote:
> Hi,
>
> is there a documentation out there that tells me which operations are atomic?


Depends on what you mean. The C# specification, for example, is clear
about what operations within the language are atomic (certain
assignments and reads, specifically).

But of course it doesn't mention any of the System.Threading.Interlocked
class, for example, which also provides for certain atomic operations.
In that sense, no...there's not a single place that all atomic
operations are documented.

> I currently have to know if increasing a System.Decimal value is an atomic operation.


An increment of any value is not guaranteed to be atomic unless you use
the Interlocked class, and the System.Decimal type is too wide to be
supported by the Interlocked class in any case.

> I guess it is not. The value is increased in one thread and read from another thread. I think I have to use a
> lock. Right?


You have to use some kind of synchronization, yes. And because it's so
wide, the System.Decimal type isn't even among those in C# that even has
atomic assignment.

There are a wide variety of possibilities, but a "lock" statement is
definitely the way to go, until you have some reason to believe you need
something cleverer and more efficient.

Pete
 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      29th Oct 2009
Peter Duniho schrieb:
> Armin Zingler wrote:
>> Hi,
>>
>> is there a documentation out there that tells me which operations are atomic?

>
> Depends on what you mean.


Atomic operations are operations on objects that are performed completely without
the possibility that another thread reads the object or a part of it in the meantime.

> The C# specification, for example, is clear about what operations within the language
> are atomic (certain assignments and reads, specifically).


I'm using VB (2008). I didn't know it's a language specific issue, therefore I posted here.
Didn't find something specific to VB.

Anyway, I've put reading/writing the value inside a Synclock-EndSynclock statement.

--
Armin




 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      29th Oct 2009
Armin Zingler wrote:
> Peter Duniho schrieb:
>> Armin Zingler wrote:
>>> Hi,
>>>
>>> is there a documentation out there that tells me which operations are atomic?

>> Depends on what you mean.

>
> Atomic operations are operations on objects that are performed completely without
> the possibility that another thread reads the object or a part of it in the meantime.


I know what "atomic operation" means. I was referring to your question
about "is there a documentation out there", and the answer depends on
what you mean by _that_. Atomic operations certainly are documented, so
the answer to your question is trivially "yes". But it might not really
be the question you meant to ask, thus my "it depends".

>> The C# specification, for example, is clear about what operations within the language
>> are atomic (certain assignments and reads, specifically).

>
> I'm using VB (2008). I didn't know it's a language specific issue, therefore I posted here.
> Didn't find something specific to VB.


I'm less familiar with VB.NET, but I would hope it would have some
similar atomic guarantees for smaller data types (e.g. System.Int32,
System.Boolean, etc.). Still, I doubt any of those would apply to
System.Decimal.

> Anyway, I've put reading/writing the value inside a Synclock-EndSynclock statement.


Should be fine.

Pete
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
atomic operations... Chris M. Thomasson Microsoft C# .NET 22 6th Aug 2009 04:14 PM
Re: Atomic operations Barry Kelly Microsoft C# .NET 0 20th Apr 2008 03:45 AM
Re: Atomic operations Jon Skeet [C# MVP] Microsoft C# .NET 4 19th Apr 2008 06:23 PM
Re: Atomic operations Michael Justin Microsoft C# .NET 1 19th Apr 2008 06:06 PM
Re: Atomic operations Arne Vajhøj Microsoft C# .NET 0 19th Apr 2008 02:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:43 PM.