Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: multitasking, multithreading?

I was told that the iPhone does not support multitasking and multithreading. This did not make sense to me, so I tested on the simulator: pthreads works, fork() doesn't. This result does make sense to me, but now I'm not sure: will the pthread library also work on the real device?

Thanks.

like image 635
noamtm Avatar asked Jul 27 '09 15:07

noamtm


People also ask

Does iOS support multi threading?

Concurrency and multithreading are a core part of iOS development. Let's dive into what makes them so powerful, and how we can leverage them in our own Cocoa Touch applications. Concurrency is the notion of multiple things happening at the same time.

What is multi threading in iOS?

Multithreading is nothing but performing tasks concurrently, by scheduling them on multiple threads to improve the application's performance. Concurrency in single-core processor vs multi-core processor (Author)

What mechanism does iOS support for multi threading?

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.


2 Answers

Multithreading will work. It's multitasking that won't. The iphone won't let more than one third party application run at once. That reasoning makes fork live outside of the application's sandbox.

You can create threads to poll sockets, read files, handle an AI player all you want, or until the performance gains start to go away.

like image 72
Ball Avatar answered Sep 18 '22 13:09

Ball


Yes, the pthread library will work on the iPhone. Alternately you can use Cocoa-native threads with NSThread. Multitasking will not work, as Apple is explicitly restricting that.

like image 28
pix0r Avatar answered Sep 16 '22 13:09

pix0r