Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For iOS, what is the difference of the Concurrency Programming Guide and the Threading Programming Guide?

The reason behind my question is that I am writing an audio units hosting app for iPhone and I need to synchronize memory access from the audio threads (writing to memory) and from the GUI thread (reading from memory).

While looking for guides to read up on the subject, I figured out that apple provides two guides for parallel programming in iOS (analogous guides are available for OS X):

  • Threading Programming Guide

  • Concurrency Programming Guide

With regards to iOS, I am a novice to parallel programming; thus it is not clear to me which of the guides I need to read, or if they cover the same matters.

like image 317
Daniel S. Avatar asked Jul 16 '13 09:07

Daniel S.


People also ask

What is the concurrency in iOS?

Concurrent Queues executes tasks one after the other without waiting on the previous task to complete. It does not mean that tasks will be all executed in one go. The execution of tasks will be based on system resources or available threads from the thread pool.

What is the concurrency how many ways you know to achieve concurrency iOS?

In iOS, there are 2 ways to achieve concurrency: Grand Central Dispatch and OperationQueue.

What mechanisms does iOS provide to support multi threading explain it with an example?

Apple provides 2 main APIs for writing multithreaded code: Grand Central Dispatch(GCD) and Operation. Behind the scenes, they use a concept known as thread pool, meaning that those API manages a large number of threads and when a task is ready to be executed, it grabs one thread from the pool to take care of the task.

What does concurrency mean programming?

Concurrency means multiple computations are happening at the same time. Concurrency is everywhere in modern programming, whether we like it or not: Multiple computers in a network. Multiple applications running on one computer. Multiple processors in a computer (today, often multiple processor cores on a single chip)


2 Answers

Concurrency Programming Guide will be your crash course in dispatch APIs (aka GCD) and NSOperations.

Threading Programming Guide will introduce you to Threads, Mutual Exclusion and Synchronization APIs and technologies. They will also cover creation of threads and interacting with Run Loops.

For your stated problem, the information in the Threading Programming Guide will be more useful.

However, much of what these guides present is of the mindset that blocking is OK. In realtime Audio, it's not OK.

AudioUnit Hosting Fundamentals is also a required read: http://developer.apple.com/library/ios/#documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/AudioUnitHostingFundamentals/AudioUnitHostingFundamentals.html

If you are animating your UI, you may need to implement/find a circular buffer implementation.

Beware - concurrency in realtime is going to be a tough subject if you are new to concurrent designs.

like image 163
justin Avatar answered Nov 15 '22 07:11

justin


This is written in a warning box inside of the Threading Programming Guide

Important: If you are developing a new application, you are encouraged to investigate the alternative OS X technologies for implementing concurrency. This is especially true if you are not already familiar with the design techniques needed to implement a threaded application. These alternative technologies simplify the amount of work you have to do to implement concurrent paths of execution and offer much better performance than traditional threads. For information about these technologies, see Concurrency Programming Guide.

So, really the difference is that the Threading Programming Guide is older and discouraged from being used in modern Objective-C.

HOWEVER, as noted in the comments, for operations that need extremely low-latency (like real-time audio editing) are not suited for NSOperation and GCD.

like image 40
borrrden Avatar answered Nov 15 '22 07:11

borrrden