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.
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.
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)
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With