Main Page | Report this Page
.NET DotNet Forum Index  »  .NET Framework Forum  »  Atomic operations...
Page 1 of 1    

Atomic operations...

Author Message
Armin Zingler...
Posted: Thu Oct 29, 2009 10:20 am
Guest
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
 
Peter Duniho...
Posted: Thu Oct 29, 2009 11:37 am
Guest
Armin Zingler wrote:
Quote:
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.

Quote:
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.

Quote:
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
 
Armin Zingler...
Posted: Thu Oct 29, 2009 2:46 pm
Guest
Peter Duniho schrieb:
Quote:
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.

Quote:
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
 
Peter Duniho...
Posted: Thu Oct 29, 2009 5:11 pm
Guest
Armin Zingler wrote:
Quote:
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".

Quote:
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.

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

Should be fine. :)

Pete
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sat Dec 05, 2009 7:03 am