Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread Nick Rogers
Hi, Please look at the following situations: 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? 2. I need to add objects to this mutable array from a secondary thread, and no other thread is

Re: Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread Abdul Sowayan
Nick, In your secondary you can use dispatch_async or dispatch_sync to schedule a block of code to execute on the main thread. Below is a simple example: dispatch_async(dispatch_get_main_queue(), ^{ // put your code to modify mutable array here }); I hope this helps. Thanks, Abdul

Re: Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread Kyle Sluder
On Aug 6, 2013, at 8:39 AM, Nick Rogers roger...@mac.com wrote: Hi, Please look at the following situations: 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, but the second half

Re: Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread Jens Alfke
On Aug 6, 2013, at 8:39 AM, Nick Rogers roger...@mac.com 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,

Re: Thread safety, some basic questions about accessing mutable objects across threads

2013-08-06 Thread David Duncan
On Aug 6, 2013, at 8:39 AM, Nick Rogers roger...@mac.com 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? 2. I need to add objects to this mutable array from a secondary thread, and