Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is assignment to pointer atomic?

Reply
Thread Tools

Is assignment to pointer atomic?

 
 
Christopher
Guest
Posts: n/a
 
      08-12-2011
I disagree with my cooworker, but neither of us can seem to find any
documentation to support our belief.
Is assignment to a pointer guarenteed to be an atomic operation?

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-12-2011
On 8/12/2011 10:47 AM, Christopher wrote:
> I disagree with my cooworker, but neither of us can seem to find any
> documentation to support our belief.
> Is assignment to a pointer guarenteed to be an atomic operation?


Not if said assignment takes more than one processor instruction,
probably. The new standard has a special section on atomics, perhaps
that's what you need to use... See the header <atomic>.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
madamemandm@yahoo.com
Guest
Posts: n/a
 
      08-12-2011
On Aug 12, 10:10*am, Victor Bazarov <(E-Mail Removed)> wrote:
> On 8/12/2011 10:47 AM, Christopher wrote:
>
> > I disagree with my cooworker, but neither of us can seem to find any
> > documentation to support our belief.
> > Is assignment to a pointer guarenteed to be an atomic operation?

>
> Not if said assignment takes more than one processor instruction,
> probably. *The new standard has a special section on atomics, perhaps
> that's what you need to use... *See the header <atomic>.
>


Even if it's a single processor instruction it's not guarenteed to be
atomic.
Read your processors manual to know when and when it isn't.

Martin Shobe
 
Reply With Quote
 
Christopher
Guest
Posts: n/a
 
      08-12-2011
On Aug 12, 11:04*am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> On Aug 12, 10:10*am, Victor Bazarov <(E-Mail Removed)> wrote:
>
> > On 8/12/2011 10:47 AM, Christopher wrote:

>
> > > I disagree with my cooworker, but neither of us can seem to find any
> > > documentation to support our belief.
> > > Is assignment to a pointer guarenteed to be an atomic operation?

>
> > Not if said assignment takes more than one processor instruction,
> > probably. *The new standard has a special section on atomics, perhaps
> > that's what you need to use... *See the header <atomic>.

>
> Even if it's a single processor instruction it's not guarenteed to be
> atomic.
> Read your processors manual to know when and when it isn't.
>
> Martin Shobe


Well, one would then conclude it depends not only on the compiler, but
also the processor. If we don't want to enforce the limitation that
the code should be compiled and executed on a particular processor,
and we wish to be as close to standard C++ as possible, then we should
indeed use a mutex around pointer assignment, no?

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-12-2011
On 8/12/2011 12:16 PM, Christopher wrote:
> On Aug 12, 11:04 am, "(E-Mail Removed)"<(E-Mail Removed)>
> wrote:
>> On Aug 12, 10:10 am, Victor Bazarov<(E-Mail Removed)> wrote:
>>
>>> On 8/12/2011 10:47 AM, Christopher wrote:

>>
>>>> I disagree with my cooworker, but neither of us can seem to find any
>>>> documentation to support our belief.
>>>> Is assignment to a pointer guarenteed to be an atomic operation?

>>
>>> Not if said assignment takes more than one processor instruction,
>>> probably. The new standard has a special section on atomics, perhaps
>>> that's what you need to use... See the header<atomic>.

>>
>> Even if it's a single processor instruction it's not guarenteed to be
>> atomic.
>> Read your processors manual to know when and when it isn't.
>>
>> Martin Shobe

>
> Well, one would then conclude it depends not only on the compiler, but
> also the processor. If we don't want to enforce the limitation that
> the code should be compiled and executed on a particular processor,
> and we wish to be as close to standard C++ as possible, then we should
> indeed use a mutex around pointer assignment, no?


If you can use a compiler that implements the new 'atomic' type, you
should. That will take care of the synchronization and exclusivity *if*
it's needed. See Chapter 29 of the new Standard.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      08-12-2011
Christopher <(E-Mail Removed)> wrote:
> I disagree with my cooworker, but neither of us can seem to find any
> documentation to support our belief.
> Is assignment to a pointer guarenteed to be an atomic operation?


AFAIK the current C++ standard takes no stance whatsoever about the
atomicity of any operation (which means it's implementation-dependent).

The next standard will have some support for explicit atomic operations,
but I'm assuming that without the explicit keyword the atomicity of any
operation will still be undefined.

Whether it's an atomic operation eg. on an x86 or an x86-64 processor
artchitecture, I don't know. (Although it would be an interesting tidbit.)
 
Reply With Quote
 
Joshua Maurice
Guest
Posts: n/a
 
      08-12-2011
On Aug 12, 7:47*am, Christopher <(E-Mail Removed)> wrote:
> I disagree with my cooworker, but neither of us can seem to find any
> documentation to support our belief.
> Is assignment to a pointer guarenteed to be an atomic operation?


What do you mean by "atomic"? There are several possible uses here.
Are we talking "atomic" in terms of signal handlers? "Atomic" in terms
of threading? "Atomic" in terms of MMIO?
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Pointer to pointer Vs References to Pointer bansalvikrant@gmail.com C++ 4 07-02-2009 10:20 AM
Assignment operator self-assignment check Chris C++ 34 09-26-2006 04:26 AM
Augument assignment versus regular assignment nagy Python 36 07-20-2006 07:24 PM
passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer jimjim C Programming 16 03-27-2006 11:03 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM



Advertisments