Re: Thread safety, some basic questions about accessing mutable objects across threads
Re: Thread safety, some basic questions about accessing mutable objects across threads
- Subject: Re: Thread safety, some basic questions about accessing mutable objects across threads
- From: Jens Alfke <email@hidden>
- Date: Tue, 06 Aug 2013 11:12:06 -0700
On Aug 6, 2013, at 8:39 AM, Nick Rogers <email@hidden> wrote:
> 1. Created a mutable array in main thread, can I read its values in a secondary thread safely, while no other thread is modifying this mutable array?
Yes. Most non-thread-safe objects don’t care what threads you call them on, so long as they’re only called on one thread at a time. So you can use locks or @synchronized blocks to coordinate access.
(The exceptions are higher-level things that use runloops or dispatch queues, such as NSURLConnection, NSStream, etc. Those usually need to be called only from the same thread/queue they’re scheduled on, because they’re also getting callbacks on that same thread/queue.)
—Jens
_______________________________________________
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