SlideShare a Scribd company logo
1 of 16
Download to read offline
[iOS	
  multithreading:GCD];
•Multithreading in iOS
•Grand Central Dispatch
•Queues
•Example
Multithreading in iOS
•Pthreads : C-based interface for creating
and manipulating threads
•NSThread : Cocoa threads
•Grand Central Dispatch : a
lightweight multithreading engine developed
by Apple Inc
•NSOperation : wrapper for task
Pthreads
NSThreads
GCD
NSOperation
complexity
low
high
abstraction level
low
high
Grand Central Dispatch
What is GCD?
• A lightweight multithreading engine
• Uses a thread pool
• Automatically optimizes threading
• Scheduling of tasks
• Uses look-free exclusion rather than mutual
exclusion
• define the tasks
• block or function
• add them to an appropriate dispatch queue
dispatch_async(queue, ^{
some_async_work();
});
thread
thread
thread
Queue based
task task task task task
queue
task task task task task
queue
task
task
task
Queue types
• Serial Queues
• only one task running at a time
• user queue or main queue
• Concurrent Queue
• tasks started in order but run concurrently
• 3 priority levels: HIGHT, DEFAULT, LOW
Frequently Used APIs
• dispatch_async(queue, block)
• dispatch_once(queue, block)
• dispatch_apply(iterations, queue, block)
• dispatch_group_async(group, queue, block)
Example
Palindromic words
• palindromic words - 回文
• is a word that reads the same forward as it does
backward :“radar”
• problem
• count the palindromic words in a dictionary
radar
wrong
way
yaw
result = 3
for (size_t index = 0; index < Words.count; index++) {
NSString *word = [Words objectAtIndex:index];
NSString *reverseString = [self reverseString:word];
if([word caseInsensitiveCompare:reverseString] == NSOrderedSame) {
self.palindromicCount++;
} else {
for (size_t i = index + 1; i < Words.count - 1; i++) {
NSString *secondWord = [Words objectAtIndex:i];
if([reverseString caseInsensitiveCompare:secondWord] == NSOrderedSame) {
self.palindromicCount += 2;
break;
}
}
}
};
dispatch_apply(Words.count, queue, ^(size_t index) {
NSString *word = [Words objectAtIndex:index];
NSString *reverseString = [self reverseString:word];
if([word caseInsensitiveCompare:reverseString] == NSOrderedSame) {
self.palindromicCount++;
} else {
for (size_t i = index + 1; i < Words.count - 1; i++) {
NSString *secondWord = [Words objectAtIndex:i];
if([reverseString caseInsensitiveCompare:secondWord] == NSOrderedSame) {
self.palindromicCount += 2;
break;
}
}
}
});
for (size_t index = 0; index < Words.count; index++) {
NSString *word = [Words objectAtIndex:index];
NSString *reverseString = [self reverseString:word];
if([word caseInsensitiveCompare:reverseString] == NSOrderedSame) {
self.palindromicCount++;
} else {
for (size_t i = index + 1; i < Words.count - 1; i++) {
NSString *secondWord = [Words objectAtIndex:i];
if([reverseString caseInsensitiveCompare:secondWord] == NSOrderedSame) {
self.palindromicCount += 2;
break;
}
}
}
};
dispatch_apply(Words.count, queue, ^(size_t index) {
NSString *word = [Words objectAtIndex:index];
NSString *reverseString = [self reverseString:word];
if([word caseInsensitiveCompare:reverseString] == NSOrderedSame) {
self.palindromicCount++;
} else {
for (size_t i = index + 1; i < Words.count - 1; i++) {
NSString *secondWord = [Words objectAtIndex:i];
if([reverseString caseInsensitiveCompare:secondWord] == NSOrderedSame) {
self.palindromicCount += 2;
break;
}
}
}
});
Results
• iPhone 5 : dual-core A6 chip
• dictionary : 25000 words
1.86 times faster
Sequential GCD
274s 147s

More Related Content

What's hot

2016 foss4 g track: developing and implementing spatial etl processes with...
2016 foss4 g track:  developing and implementing  spatial etl processes  with...2016 foss4 g track:  developing and implementing  spatial etl processes  with...
2016 foss4 g track: developing and implementing spatial etl processes with...GIS in the Rockies
 
MongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB
 
Powering Rails Application With PostgreSQL
Powering Rails Application With PostgreSQLPowering Rails Application With PostgreSQL
Powering Rails Application With PostgreSQLicicletech
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structuresamix3k
 
SSTable Reader Cassandra Day Denver 2014
SSTable Reader Cassandra Day Denver 2014SSTable Reader Cassandra Day Denver 2014
SSTable Reader Cassandra Day Denver 2014Ben Vanberg
 
Redis data modeling examples
Redis data modeling examplesRedis data modeling examples
Redis data modeling examplesTerry Cho
 
Look Mommy, No GC! (TechDays NL 2017)
Look Mommy, No GC! (TechDays NL 2017)Look Mommy, No GC! (TechDays NL 2017)
Look Mommy, No GC! (TechDays NL 2017)Dina Goldshtein
 
Locomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeLocomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeMichael Mior
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
AWS Fargate in practice. How to run containers without managing EC2 instances
AWS Fargate in practice. How to run containers without managing EC2 instancesAWS Fargate in practice. How to run containers without managing EC2 instances
AWS Fargate in practice. How to run containers without managing EC2 instancesMax Borysov
 
Tweaking performance on high-load projects
Tweaking performance on high-load projectsTweaking performance on high-load projects
Tweaking performance on high-load projectsDmitriy Dumanskiy
 
Streaming Data with scalaz-stream
Streaming Data with scalaz-streamStreaming Data with scalaz-stream
Streaming Data with scalaz-streamGaryCoady
 
Handling 20 billion requests a month
Handling 20 billion requests a monthHandling 20 billion requests a month
Handling 20 billion requests a monthDmitriy Dumanskiy
 
MongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingMongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingJason Terpko
 
Azure sql insert perf
Azure sql insert perfAzure sql insert perf
Azure sql insert perfMornè Blake
 
{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}Anthony Levings
 
Triggers In MongoDB
Triggers In MongoDBTriggers In MongoDB
Triggers In MongoDBJason Terpko
 
Memory Management & Garbage Collection
Memory Management & Garbage CollectionMemory Management & Garbage Collection
Memory Management & Garbage CollectionAbhishek Sur
 

What's hot (20)

2016 foss4 g track: developing and implementing spatial etl processes with...
2016 foss4 g track:  developing and implementing  spatial etl processes  with...2016 foss4 g track:  developing and implementing  spatial etl processes  with...
2016 foss4 g track: developing and implementing spatial etl processes with...
 
Data perisistence in iOS
Data perisistence in iOSData perisistence in iOS
Data perisistence in iOS
 
MongoDB Shell Tips & Tricks
MongoDB Shell Tips & TricksMongoDB Shell Tips & Tricks
MongoDB Shell Tips & Tricks
 
Powering Rails Application With PostgreSQL
Powering Rails Application With PostgreSQLPowering Rails Application With PostgreSQL
Powering Rails Application With PostgreSQL
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structures
 
SSTable Reader Cassandra Day Denver 2014
SSTable Reader Cassandra Day Denver 2014SSTable Reader Cassandra Day Denver 2014
SSTable Reader Cassandra Day Denver 2014
 
Redis data modeling examples
Redis data modeling examplesRedis data modeling examples
Redis data modeling examples
 
Look Mommy, No GC! (TechDays NL 2017)
Look Mommy, No GC! (TechDays NL 2017)Look Mommy, No GC! (TechDays NL 2017)
Look Mommy, No GC! (TechDays NL 2017)
 
Locomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeLocomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database code
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
AWS Fargate in practice. How to run containers without managing EC2 instances
AWS Fargate in practice. How to run containers without managing EC2 instancesAWS Fargate in practice. How to run containers without managing EC2 instances
AWS Fargate in practice. How to run containers without managing EC2 instances
 
Onyx
OnyxOnyx
Onyx
 
Tweaking performance on high-load projects
Tweaking performance on high-load projectsTweaking performance on high-load projects
Tweaking performance on high-load projects
 
Streaming Data with scalaz-stream
Streaming Data with scalaz-streamStreaming Data with scalaz-stream
Streaming Data with scalaz-stream
 
Handling 20 billion requests a month
Handling 20 billion requests a monthHandling 20 billion requests a month
Handling 20 billion requests a month
 
MongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingMongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and Merging
 
Azure sql insert perf
Azure sql insert perfAzure sql insert perf
Azure sql insert perf
 
{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}
 
Triggers In MongoDB
Triggers In MongoDBTriggers In MongoDB
Triggers In MongoDB
 
Memory Management & Garbage Collection
Memory Management & Garbage CollectionMemory Management & Garbage Collection
Memory Management & Garbage Collection
 

Similar to Presentation 2

Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)MongoDB
 
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...Ruby Meditation
 
Mythbusting: Understanding How We Measure Performance at MongoDB
Mythbusting: Understanding How We Measure Performance at MongoDBMythbusting: Understanding How We Measure Performance at MongoDB
Mythbusting: Understanding How We Measure Performance at MongoDBMongoDB
 
Scalding big ADta
Scalding big ADtaScalding big ADta
Scalding big ADtab0ris_1
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
Introducing Apache Spark's Data Frames and Dataset APIs workshop series
Introducing Apache Spark's Data Frames and Dataset APIs workshop seriesIntroducing Apache Spark's Data Frames and Dataset APIs workshop series
Introducing Apache Spark's Data Frames and Dataset APIs workshop seriesHolden Karau
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOSPetr Dvorak
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development IntroLuis Azevedo
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable CodeBaidu, Inc.
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)Paul Chao
 

Similar to Presentation 2 (20)

iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
 
Unit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptxUnit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptx
 
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
Mythbusting: Understanding How We Measure Performance at MongoDB
Mythbusting: Understanding How We Measure Performance at MongoDBMythbusting: Understanding How We Measure Performance at MongoDB
Mythbusting: Understanding How We Measure Performance at MongoDB
 
Scalding big ADta
Scalding big ADtaScalding big ADta
Scalding big ADta
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 
Day 1
Day 1Day 1
Day 1
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
Introducing Apache Spark's Data Frames and Dataset APIs workshop series
Introducing Apache Spark's Data Frames and Dataset APIs workshop seriesIntroducing Apache Spark's Data Frames and Dataset APIs workshop series
Introducing Apache Spark's Data Frames and Dataset APIs workshop series
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
Performance patterns
Performance patternsPerformance patterns
Performance patterns
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
 

Recently uploaded

Models in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceModels in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceMonica Sydney
 
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...call girls kolkata
 
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls AgencyHire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls AgencyNitya salvi
 
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Nitya salvi
 
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyNitya salvi
 
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...Call Girls Mumbai
 
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service AvailableCall Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Turbhe Female Escorts 09167354423 Turbhe Escorts,Call Girls In Turbhe
Turbhe Female Escorts 09167354423  Turbhe Escorts,Call Girls In TurbheTurbhe Female Escorts 09167354423  Turbhe Escorts,Call Girls In Turbhe
Turbhe Female Escorts 09167354423 Turbhe Escorts,Call Girls In TurbhePriya Reddy
 
Dahod Call Girl 📞 8617370543 Low Price Genuine Service
Dahod Call Girl 📞 8617370543 Low Price Genuine ServiceDahod Call Girl 📞 8617370543 Low Price Genuine Service
Dahod Call Girl 📞 8617370543 Low Price Genuine ServiceNitya salvi
 
Dubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in DubaiDubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in DubaiMonica Sydney
 
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls AgencyHire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls AgencyNitya salvi
 
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls AgencyHire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls AgencyNitya salvi
 
Call girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girlsCall girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girlsMonica Sydney
 
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...Priya Reddy
 
Book ☎️ 8617370543 Call Girls in Bharuch and escort services 24x7
Book ☎️ 8617370543 Call Girls in Bharuch and escort services 24x7Book ☎️ 8617370543 Call Girls in Bharuch and escort services 24x7
Book ☎️ 8617370543 Call Girls in Bharuch and escort services 24x7Nitya salvi
 
Ambassa Escorts | 8617370543 call girls service for all Users
Ambassa Escorts | 8617370543 call girls service for all UsersAmbassa Escorts | 8617370543 call girls service for all Users
Ambassa Escorts | 8617370543 call girls service for all UsersNitya salvi
 
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...call girls kolkata
 
Dubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiDubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiMonica Sydney
 

Recently uploaded (20)

Models in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl ServiceModels in Deira 0567006274 Deira Call girl Service
Models in Deira 0567006274 Deira Call girl Service
 
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
 
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
Call Girls in Perumbavoor / 9332606886 Genuine Call girls with real Photos an...
 
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls AgencyHire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
Hire 💕 8617370543 Auraiya Call Girls Service Call Girls Agency
 
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
Call Girls In Amreli Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service Enjoy...
 
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
 
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
 
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service AvailableCall Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
Call Girls Belonia Just Call 📞 8617370543 Top Class Call Girl Service Available
 
Turbhe Female Escorts 09167354423 Turbhe Escorts,Call Girls In Turbhe
Turbhe Female Escorts 09167354423  Turbhe Escorts,Call Girls In TurbheTurbhe Female Escorts 09167354423  Turbhe Escorts,Call Girls In Turbhe
Turbhe Female Escorts 09167354423 Turbhe Escorts,Call Girls In Turbhe
 
Dahod Call Girl 📞 8617370543 Low Price Genuine Service
Dahod Call Girl 📞 8617370543 Low Price Genuine ServiceDahod Call Girl 📞 8617370543 Low Price Genuine Service
Dahod Call Girl 📞 8617370543 Low Price Genuine Service
 
Dubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in DubaiDubai Call girls Service 0524076003 Call girls services in Dubai
Dubai Call girls Service 0524076003 Call girls services in Dubai
 
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls AgencyHire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
 
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
 
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls AgencyHire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
Hire 💕 8617370543 Dhalai Call Girls Service Call Girls Agency
 
Call girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girlsCall girls Service in Deira 0507330913 Deira Call girls
Call girls Service in Deira 0507330913 Deira Call girls
 
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
 
Book ☎️ 8617370543 Call Girls in Bharuch and escort services 24x7
Book ☎️ 8617370543 Call Girls in Bharuch and escort services 24x7Book ☎️ 8617370543 Call Girls in Bharuch and escort services 24x7
Book ☎️ 8617370543 Call Girls in Bharuch and escort services 24x7
 
Ambassa Escorts | 8617370543 call girls service for all Users
Ambassa Escorts | 8617370543 call girls service for all UsersAmbassa Escorts | 8617370543 call girls service for all Users
Ambassa Escorts | 8617370543 call girls service for all Users
 
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
Call Girls Kozhikode - 9332606886 Our call girls are sure to provide you with...
 
Dubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in DubaiDubai Call girls Service 0524076003 Call girls in Dubai
Dubai Call girls Service 0524076003 Call girls in Dubai
 

Presentation 2

  • 2. •Multithreading in iOS •Grand Central Dispatch •Queues •Example
  • 4. •Pthreads : C-based interface for creating and manipulating threads •NSThread : Cocoa threads •Grand Central Dispatch : a lightweight multithreading engine developed by Apple Inc •NSOperation : wrapper for task
  • 7. What is GCD? • A lightweight multithreading engine • Uses a thread pool • Automatically optimizes threading • Scheduling of tasks • Uses look-free exclusion rather than mutual exclusion
  • 8. • define the tasks • block or function • add them to an appropriate dispatch queue dispatch_async(queue, ^{ some_async_work(); });
  • 9. thread thread thread Queue based task task task task task queue task task task task task queue task task task
  • 10. Queue types • Serial Queues • only one task running at a time • user queue or main queue • Concurrent Queue • tasks started in order but run concurrently • 3 priority levels: HIGHT, DEFAULT, LOW
  • 11. Frequently Used APIs • dispatch_async(queue, block) • dispatch_once(queue, block) • dispatch_apply(iterations, queue, block) • dispatch_group_async(group, queue, block)
  • 13. Palindromic words • palindromic words - 回文 • is a word that reads the same forward as it does backward :“radar” • problem • count the palindromic words in a dictionary radar wrong way yaw result = 3
  • 14. for (size_t index = 0; index < Words.count; index++) { NSString *word = [Words objectAtIndex:index]; NSString *reverseString = [self reverseString:word]; if([word caseInsensitiveCompare:reverseString] == NSOrderedSame) { self.palindromicCount++; } else { for (size_t i = index + 1; i < Words.count - 1; i++) { NSString *secondWord = [Words objectAtIndex:i]; if([reverseString caseInsensitiveCompare:secondWord] == NSOrderedSame) { self.palindromicCount += 2; break; } } } }; dispatch_apply(Words.count, queue, ^(size_t index) { NSString *word = [Words objectAtIndex:index]; NSString *reverseString = [self reverseString:word]; if([word caseInsensitiveCompare:reverseString] == NSOrderedSame) { self.palindromicCount++; } else { for (size_t i = index + 1; i < Words.count - 1; i++) { NSString *secondWord = [Words objectAtIndex:i]; if([reverseString caseInsensitiveCompare:secondWord] == NSOrderedSame) { self.palindromicCount += 2; break; } } } });
  • 15. for (size_t index = 0; index < Words.count; index++) { NSString *word = [Words objectAtIndex:index]; NSString *reverseString = [self reverseString:word]; if([word caseInsensitiveCompare:reverseString] == NSOrderedSame) { self.palindromicCount++; } else { for (size_t i = index + 1; i < Words.count - 1; i++) { NSString *secondWord = [Words objectAtIndex:i]; if([reverseString caseInsensitiveCompare:secondWord] == NSOrderedSame) { self.palindromicCount += 2; break; } } } }; dispatch_apply(Words.count, queue, ^(size_t index) { NSString *word = [Words objectAtIndex:index]; NSString *reverseString = [self reverseString:word]; if([word caseInsensitiveCompare:reverseString] == NSOrderedSame) { self.palindromicCount++; } else { for (size_t i = index + 1; i < Words.count - 1; i++) { NSString *secondWord = [Words objectAtIndex:i]; if([reverseString caseInsensitiveCompare:secondWord] == NSOrderedSame) { self.palindromicCount += 2; break; } } } });
  • 16. Results • iPhone 5 : dual-core A6 chip • dictionary : 25000 words 1.86 times faster Sequential GCD 274s 147s