SlideShare a Scribd company logo
Multitasking in iOS Alexander Butenko, Ciklum
What is a multitasking? § Multitasking  is a method where multiple tasks share resources such as a  CPU . In the case of a computer with a single CPU, only one task is said to be  running  at any point in time, meaning that the CPU is actively executing instructions for that task. Multitasking solves the problem by  scheduling  which task may be the one running at any given time, and when another waiting task gets a turn.
Multitasking goals § Improvement of application’s perceived responsiveness. § Improvement of application’s real-time performance on multicore systems.
Basics To run program system need to make environment for task execution. This environment consists of memory resources, input-output posibillity, access to different system resources including kernel services. This environment is called  process .  In contrast to the process, which is equipped to create their own address space and context,  thread  uses the address space of the parent process and part of its context .  So independent threads created within a single process can access the same data.
Threads advantages § Thread need less system resources (time for creation and physical resources) than processes § Interthread communication easier than interprocess communication
Threads disadvantages § Thread  add uncertainty to your code §  Threads still introduce a tremendous amount of overhead to your process
Threads alternatives § Operation objects § Grand Central Dispatch (GCD) § Idle-time notifications § Asynchronous functions § Timers
Threads in iOS §  Сocoa threads § POSIX threads
Сocoa threads Cocoa implements threads using the  NSThread  class: 1)  [NSThread  detachNewThreadSelector:@selector(myThreadMainMethod:) toTarget:self withObject:nil]; 2)  NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(myThreadMainMethod:) object:nil];  [myThread start]; // Actually create the thread
POSIX threads POSIX threads provide a C-based interface for creating threads.  This technology can actually be used in any type of application (including Cocoa and Cocoa Touch applications) and might be more convenient if you are writing your software for multiple platforms. The POSIX routine you use to create threads is called, appropriately enough,  pthread_create .
 
Thread entry routine §  Creating an Autorelease Pool § Setting Up an Exception Handler § Setting Up a Run Loop
Runloop
Input sources §  Port-Based Sources § Custom Input Sources § Cocoa Perform Selector Sources
 
Synchronization §  Atomic Operations § Memory Barriers and Volatile Variables § Locks § Conditions § Perform Selector Routines § Locks
Atomic operations Atomic operations are a simple form of synchronization that work on simple data types. The advantage of atomic operations is that they do not block competing threads. For simple operations, such as incrementing a counter variable, this can lead to much better performance than taking a lock.
Memory barriers and Volatile variables §  A memory barrier acts like a fence, forcing the processor to complete any load and store operations positioned in front of the barrier before it is allowed to perform load and store operations positioned after the barrier. §  Applying the  volatile  keyword to a variable forces the compiler to load that variable from memory each time it is used.
Locks §  Mutex § Recursive lock § Read-write lock § Distributed lock § Spin lock § Double-checked lock
Conditions A condition is another type of semaphore that allows threads to signal each other when a certain condition is true. Conditions are typically used to indicate the availability of a resource or to ensure that tasks are performed in a specific order. When a thread tests a condition, it blocks unless that condition is already true.
Interthread Communication §  Direct messaging § Global variables, shared memory, and objects § Conditions § Run loop sources § Ports and sockets § Message queues § Cocoa distributed objects
Operation objects § Operation object is a wrapper for a task that would normally be executed on a secondary thread.  §  This wrapper hides the thread management aspects of performing the task, leaving you free to focus on the task itself.
Dispatch queues §  With GCD, you define the task you want to perform and add it to a work queue, which handles the scheduling of your task on an appropriate thread.  §  Work queues take into account the number of available cores and the current load to execute your tasks more efficiently than you could do yourself using threads.

More Related Content

PDF
Rise of node(Part I)
Goddy Zhao
 
PDF
NodeJS ecosystem
Yukti Kaura
 
PPTX
Introduction to Node.js
Winston Hsieh
 
PDF
Understanding the Single Thread Event Loop
TorontoNodeJS
 
PPTX
Node.js Workshop - Sela SDP 2015
Nir Noy
 
ODP
MongoDB Devops Madrid February 2012
Juan Vicente Herrera Ruiz de Alejo
 
PPTX
Java-7 Concurrency
Masudul Haque
 
ODP
Introduction to Mesos
koboltmarky
 
Rise of node(Part I)
Goddy Zhao
 
NodeJS ecosystem
Yukti Kaura
 
Introduction to Node.js
Winston Hsieh
 
Understanding the Single Thread Event Loop
TorontoNodeJS
 
Node.js Workshop - Sela SDP 2015
Nir Noy
 
MongoDB Devops Madrid February 2012
Juan Vicente Herrera Ruiz de Alejo
 
Java-7 Concurrency
Masudul Haque
 
Introduction to Mesos
koboltmarky
 

What's hot (20)

DOCX
Node js getting started
Pallavi Srivastava
 
PDF
Distributed system coordination by zookeeper and introduction to kazoo python...
Jimmy Lai
 
PPTX
Intro to node and mongodb 1
Mohammad Qureshi
 
PPTX
Node js for beginners
Arjun Sreekumar
 
PDF
Basic Understanding and Implement of Node.js
Gary Yeh
 
PDF
Node.js Enterprise Middleware
Behrad Zari
 
PDF
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
PDF
A Python Petting Zoo
devondjones
 
PPTX
Introduction to Apache ZooKeeper
Saurav Haloi
 
PDF
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
PDF
Distributed Coordination with Python
OSCON Byrum
 
PPTX
Apache zookeeper seminar_trinh_viet_dung_03_2016
Viet-Dung TRINH
 
ODP
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham
 
PDF
Nodejs presentation
Arvind Devaraj
 
PPTX
Building and Scaling Node.js Applications
Ohad Kravchick
 
PDF
Containers > VMs
David Timothy Strauss
 
PDF
NodeJS for Beginner
Apaichon Punopas
 
PDF
Apache Zookeeper
Nguyen Quang
 
PDF
Node
Arjun Raj
 
PPTX
Java script at backend nodejs
Amit Thakkar
 
Node js getting started
Pallavi Srivastava
 
Distributed system coordination by zookeeper and introduction to kazoo python...
Jimmy Lai
 
Intro to node and mongodb 1
Mohammad Qureshi
 
Node js for beginners
Arjun Sreekumar
 
Basic Understanding and Implement of Node.js
Gary Yeh
 
Node.js Enterprise Middleware
Behrad Zari
 
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
A Python Petting Zoo
devondjones
 
Introduction to Apache ZooKeeper
Saurav Haloi
 
Node Js, AngularJs and Express Js Tutorial
PHP Support
 
Distributed Coordination with Python
OSCON Byrum
 
Apache zookeeper seminar_trinh_viet_dung_03_2016
Viet-Dung TRINH
 
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham
 
Nodejs presentation
Arvind Devaraj
 
Building and Scaling Node.js Applications
Ohad Kravchick
 
Containers > VMs
David Timothy Strauss
 
NodeJS for Beginner
Apaichon Punopas
 
Apache Zookeeper
Nguyen Quang
 
Node
Arjun Raj
 
Java script at backend nodejs
Amit Thakkar
 
Ad

Similar to Aleksandr_Butenko_Mobile_Development (20)

PDF
Threading Programming Guide
DEVTYPE
 
PDF
Multithreading and Parallelism on iOS [MobOS 2013]
Kuba Břečka
 
PDF
Concurrent/ parallel programming
Tausun Akhtary
 
PDF
Grand Central Dispatch and multi-threading [iCONdev 2014]
Kuba Břečka
 
KEY
Threading in iOS / Cocoa Touch
mobiledeveloperpl
 
PDF
Multithreading on iOS
Make School
 
PPTX
Pune-Cocoa: Blocks and GCD
Prashant Rane
 
PPTX
Multithreading
sagsharma
 
PPT
Java
mdfkhan625
 
PPTX
Grand Central Dispatch
cqtt191
 
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
Jonathan Engelsma
 
PPT
Java Multithreading
Rajkattamuri
 
PPT
Java multithreading
Mohammed625
 
PPTX
Interactions complicate debugging
Syed Zaid Irshad
 
PPT
Multithreading
F K
 
ODP
Multithreading 101
Tim Penhey
 
PPT
Java multi threading
Raja Sekhar
 
PDF
threads (1).pdfmjlkjfwjgliwiufuaiusyroayr
abhinandpk2405
 
PDF
CH04.pdf
ImranKhan880955
 
PDF
Multithreading 101
Tim Penhey
 
Threading Programming Guide
DEVTYPE
 
Multithreading and Parallelism on iOS [MobOS 2013]
Kuba Břečka
 
Concurrent/ parallel programming
Tausun Akhtary
 
Grand Central Dispatch and multi-threading [iCONdev 2014]
Kuba Břečka
 
Threading in iOS / Cocoa Touch
mobiledeveloperpl
 
Multithreading on iOS
Make School
 
Pune-Cocoa: Blocks and GCD
Prashant Rane
 
Multithreading
sagsharma
 
Grand Central Dispatch
cqtt191
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 7)
Jonathan Engelsma
 
Java Multithreading
Rajkattamuri
 
Java multithreading
Mohammed625
 
Interactions complicate debugging
Syed Zaid Irshad
 
Multithreading
F K
 
Multithreading 101
Tim Penhey
 
Java multi threading
Raja Sekhar
 
threads (1).pdfmjlkjfwjgliwiufuaiusyroayr
abhinandpk2405
 
CH04.pdf
ImranKhan880955
 
Multithreading 101
Tim Penhey
 
Ad

More from Ciklum (8)

PPTX
CiklumNETSat10122011:DmitriyMindra-DCI
Ciklum
 
PPT
Pavel_Kravchenko_Mobile Development
Ciklum
 
PPTX
Aleksey_Demedetskiy_Jenkins
Ciklum
 
PPT
Speakers' corner_Kharkov
Ciklum
 
PPT
Speakers' corner
Ciklum
 
PPTX
Mikhail Valkov_Antipatterns
Ciklum
 
PPT
Dmitriy Pasko_NuGet - package management for .NET
Ciklum
 
PPTX
Anders Sorensen_Optimizing development in an offshore context
Ciklum
 
CiklumNETSat10122011:DmitriyMindra-DCI
Ciklum
 
Pavel_Kravchenko_Mobile Development
Ciklum
 
Aleksey_Demedetskiy_Jenkins
Ciklum
 
Speakers' corner_Kharkov
Ciklum
 
Speakers' corner
Ciklum
 
Mikhail Valkov_Antipatterns
Ciklum
 
Dmitriy Pasko_NuGet - package management for .NET
Ciklum
 
Anders Sorensen_Optimizing development in an offshore context
Ciklum
 

Recently uploaded (20)

PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
The Future of Artificial Intelligence (AI)
Mukul
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 

Aleksandr_Butenko_Mobile_Development

  • 1. Multitasking in iOS Alexander Butenko, Ciklum
  • 2. What is a multitasking? § Multitasking is a method where multiple tasks share resources such as a CPU . In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is actively executing instructions for that task. Multitasking solves the problem by scheduling which task may be the one running at any given time, and when another waiting task gets a turn.
  • 3. Multitasking goals § Improvement of application’s perceived responsiveness. § Improvement of application’s real-time performance on multicore systems.
  • 4. Basics To run program system need to make environment for task execution. This environment consists of memory resources, input-output posibillity, access to different system resources including kernel services. This environment is called process . In contrast to the process, which is equipped to create their own address space and context, thread uses the address space of the parent process and part of its context . So independent threads created within a single process can access the same data.
  • 5. Threads advantages § Thread need less system resources (time for creation and physical resources) than processes § Interthread communication easier than interprocess communication
  • 6. Threads disadvantages § Thread add uncertainty to your code § Threads still introduce a tremendous amount of overhead to your process
  • 7. Threads alternatives § Operation objects § Grand Central Dispatch (GCD) § Idle-time notifications § Asynchronous functions § Timers
  • 8. Threads in iOS § Сocoa threads § POSIX threads
  • 9. Сocoa threads Cocoa implements threads using the NSThread class: 1) [NSThread detachNewThreadSelector:@selector(myThreadMainMethod:) toTarget:self withObject:nil]; 2) NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(myThreadMainMethod:) object:nil]; [myThread start]; // Actually create the thread
  • 10. POSIX threads POSIX threads provide a C-based interface for creating threads. This technology can actually be used in any type of application (including Cocoa and Cocoa Touch applications) and might be more convenient if you are writing your software for multiple platforms. The POSIX routine you use to create threads is called, appropriately enough, pthread_create .
  • 11.  
  • 12. Thread entry routine § Creating an Autorelease Pool § Setting Up an Exception Handler § Setting Up a Run Loop
  • 14. Input sources § Port-Based Sources § Custom Input Sources § Cocoa Perform Selector Sources
  • 15.  
  • 16. Synchronization § Atomic Operations § Memory Barriers and Volatile Variables § Locks § Conditions § Perform Selector Routines § Locks
  • 17. Atomic operations Atomic operations are a simple form of synchronization that work on simple data types. The advantage of atomic operations is that they do not block competing threads. For simple operations, such as incrementing a counter variable, this can lead to much better performance than taking a lock.
  • 18. Memory barriers and Volatile variables § A memory barrier acts like a fence, forcing the processor to complete any load and store operations positioned in front of the barrier before it is allowed to perform load and store operations positioned after the barrier. § Applying the volatile keyword to a variable forces the compiler to load that variable from memory each time it is used.
  • 19. Locks § Mutex § Recursive lock § Read-write lock § Distributed lock § Spin lock § Double-checked lock
  • 20. Conditions A condition is another type of semaphore that allows threads to signal each other when a certain condition is true. Conditions are typically used to indicate the availability of a resource or to ensure that tasks are performed in a specific order. When a thread tests a condition, it blocks unless that condition is already true.
  • 21. Interthread Communication § Direct messaging § Global variables, shared memory, and objects § Conditions § Run loop sources § Ports and sockets § Message queues § Cocoa distributed objects
  • 22. Operation objects § Operation object is a wrapper for a task that would normally be executed on a secondary thread. § This wrapper hides the thread management aspects of performing the task, leaving you free to focus on the task itself.
  • 23. Dispatch queues § With GCD, you define the task you want to perform and add it to a work queue, which handles the scheduling of your task on an appropriate thread. § Work queues take into account the number of available cores and the current load to execute your tasks more efficiently than you could do yourself using threads.

Editor's Notes

  • #4: Посмотреть, что это за боги EventLoop
  • #5: Пример с пареметризацией пункта меню
  • #8: NSUndoManager почитать
  • #9: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #10: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #11: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #12: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #13: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #14: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #15: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #16: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #17: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #18: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #19: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #20: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #21: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #22: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #23: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память
  • #24: Посмотреть RunTime Programming Guide Посмотреть на временные задержки вызова операций На возврат результата из метода, инвокешна и селектора На сохранение инвокешна на диск или в память