-1

I want to have some clarify about it. I know that I need to update UI in main thread. Are there anything else?

What I need to do in main thread and what in background threads?

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • possible duplicate of [Help with multi-threading on iOS?](http://stackoverflow.com/questions/4360591/help-with-multi-threading-on-ios) – Balram Tiwari May 10 '14 at 03:36

2 Answers2

1

In addition to UI updates, as a broader thread-safety strategy, people will often dispatch their model updates to the main thread as a simple synchronization technique, too.

Synchronization is ultimately the process of assuring that an object is in a logically consistent state, i.e. that while an object is being used on one thread, that it isn't simultaneously being mutated by some other thread. Traditionally, one might accomplish this by employing locks (e.g. NSLock, @synchronized, etc.) but you can also achieve this by dispatching all interaction with a particular object to a serial queue. While you can replace locks with a dedicated serial queue, in many cases it's just as easy to dispatch all updates to the object in the main queue. It turns out to be a convenient way to synchronize your model objects that might otherwise would have been used/mutated by separate threads.

For more information, see the Eliminating Lock-Based Code section in the Migrating Away from Threads chapter of the Concurrency Programming Guide.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
0

It all depends. Modern OS take advantage of the multiple cores or virtual CPUs, so when you run your app, the OS defines what to run where, and usually your program runs in multiple threads. If there are data dependencies, then you should run things in specific threads, unless you run stuff in background or different threads, then you can implement notifications to ensure that the data you need is ready when you need it. You should also take into account the thread safe nature of the the different ways to define properties. So... other than the UI stuff in main, you can run anything pretty much wherever you want.

eharo2
  • 2,553
  • 1
  • 29
  • 39