Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pointer assignment inherently atomic ?




can anyone help me with my question of the day:

are pointer assignments inherently atomic ?


i have an NSMutableArray that gets periodically rebuilt in a background thread.
the main thread or any of several other threads may want read access to it at any time.


when i rebuild it in the background thread, i am actually building a new, separate array and once i'm done i swap in the new one for the old one:

oldarray = realarray;
realarray = newarray; // the swap
[oldarray release];


now i could put locks around every place where i read it or write to it (lots of code clutter in this particular case), but i'm thinking that it may not be necessary since the swap will ultimately boil down to (i think) a single, indivisible cpu instruction (....maybe).


is this a fair assumption?

note that i haven't had any crashes or bugs related to this so far (over the course of several weeks of development), but i'm worried it may just be luck.

any input would be great.

thanks.

- chase



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.