pointer assignment inherently atomic ?
pointer assignment inherently atomic ?
- Subject: pointer assignment inherently atomic ?
- From: "Chase" <email@hidden>
- Date: Fri, 10 Aug 2007 19:52:49 +0000
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:
This email sent to email@hidden