SlideShare une entreprise Scribd logo
1  sur  21
Blocks
Grand Central Dispatch
Blocks / GCD

• Objective-C 2.1
• Snow Leopard
• iOS 4
Blocks


• lambda, closure
• Lisp, SmallTalk, Ruby
• C, C++, Objective-C
^
DEMO
Block

• Blocks Objective-C
• Block
 •           copy

 •      release        Block
Block

• Blocks
           retain

•      Block
                    __block
Blocks vs Function Pointer

  •   vs

  •
  •
Grand Central Dispatch

•
•
•
•   Blocks
GCD
GCD
GCD
GCD Queue

• Main dispatch queue
• Concurrent queue
• Serial queue
Main dispatch Queue
Concurrent Queue
Serial Queue
GCD Group

• dispatch_group_create
• dispatch_group_async
• dispatch_group_wait
• Thread join
GCD Sources

•
    •
• Event handler   GCD Queue
GCD Source
DEMO
•
    • Introducing Blocks and Grand Central Dispatch
    • Concurrency Programming Guide
    • Grand Central Dispatch (GCD) Reference
• WWDC 2010: Session 206, 211

Contenu connexe

Tendances

Fedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIUFedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIU
Andrey Vagin
 
OpenStack Nova Scheduler
OpenStack Nova Scheduler OpenStack Nova Scheduler
OpenStack Nova Scheduler
Peeyush Gupta
 

Tendances (20)

Ceph BlueStore - новый тип хранилища в Ceph / Максим Воронцов, (Redsys)
Ceph BlueStore - новый тип хранилища в Ceph / Максим Воронцов, (Redsys)Ceph BlueStore - новый тип хранилища в Ceph / Максим Воронцов, (Redsys)
Ceph BlueStore - новый тип хранилища в Ceph / Максим Воронцов, (Redsys)
 
Fedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIUFedora Virtualization Day: Linux Containers & CRIU
Fedora Virtualization Day: Linux Containers & CRIU
 
CRIU: Time and Space Travel for Linux Containers
CRIU: Time and Space Travel for Linux ContainersCRIU: Time and Space Travel for Linux Containers
CRIU: Time and Space Travel for Linux Containers
 
OpenStack Tokyo Meeup - Gluster Storage Day
OpenStack Tokyo Meeup - Gluster Storage DayOpenStack Tokyo Meeup - Gluster Storage Day
OpenStack Tokyo Meeup - Gluster Storage Day
 
Kubernetes dealing with storage and persistence
Kubernetes  dealing with storage and persistenceKubernetes  dealing with storage and persistence
Kubernetes dealing with storage and persistence
 
Data Reduction for Gluster with VDO
Data Reduction for Gluster with VDOData Reduction for Gluster with VDO
Data Reduction for Gluster with VDO
 
Arbiter volumes in gluster
Arbiter volumes in glusterArbiter volumes in gluster
Arbiter volumes in gluster
 
Gluster as Block Store in Containers
Gluster as Block Store in ContainersGluster as Block Store in Containers
Gluster as Block Store in Containers
 
OpenStack Cinder Overview - Havana Release
OpenStack Cinder Overview - Havana ReleaseOpenStack Cinder Overview - Havana Release
OpenStack Cinder Overview - Havana Release
 
Gluster and Kubernetes
Gluster and KubernetesGluster and Kubernetes
Gluster and Kubernetes
 
Disque: a detailed overview of the distributed implementation - Salvatore San...
Disque: a detailed overview of the distributed implementation - Salvatore San...Disque: a detailed overview of the distributed implementation - Salvatore San...
Disque: a detailed overview of the distributed implementation - Salvatore San...
 
Zun presentation (OpenStack Barcelona summit)
Zun presentation (OpenStack Barcelona summit)Zun presentation (OpenStack Barcelona summit)
Zun presentation (OpenStack Barcelona summit)
 
Kkeithley ufonfs-gluster summit
Kkeithley ufonfs-gluster summitKkeithley ufonfs-gluster summit
Kkeithley ufonfs-gluster summit
 
Containers for the Enterprise: Delivering OpenShift on OpenStack for Performa...
Containers for the Enterprise: Delivering OpenShift on OpenStack for Performa...Containers for the Enterprise: Delivering OpenShift on OpenStack for Performa...
Containers for the Enterprise: Delivering OpenShift on OpenStack for Performa...
 
RBD: What will the future bring? - Jason Dillaman
RBD: What will the future bring? - Jason DillamanRBD: What will the future bring? - Jason Dillaman
RBD: What will the future bring? - Jason Dillaman
 
OpenStack Nova Scheduler
OpenStack Nova Scheduler OpenStack Nova Scheduler
OpenStack Nova Scheduler
 
OpenStack Storage Overview
OpenStack Storage OverviewOpenStack Storage Overview
OpenStack Storage Overview
 
Docker volume-isolator-in-mesos
Docker volume-isolator-in-mesosDocker volume-isolator-in-mesos
Docker volume-isolator-in-mesos
 
Disruptor 2015-12-22 @ java.il
Disruptor 2015-12-22 @ java.ilDisruptor 2015-12-22 @ java.il
Disruptor 2015-12-22 @ java.il
 
reInvent 2021 Recap and k9s review
reInvent 2021 Recap and k9s reviewreInvent 2021 Recap and k9s review
reInvent 2021 Recap and k9s review
 

En vedette

Professional Work
Professional WorkProfessional Work
Professional Work
onite
 
Orient Advertising, Profile
Orient Advertising, ProfileOrient Advertising, Profile
Orient Advertising, Profile
Henna Shaykh
 
Khi internation food fest 2012 - for media partner
Khi internation food fest   2012 - for media partnerKhi internation food fest   2012 - for media partner
Khi internation food fest 2012 - for media partner
Henna Shaykh
 
Symfony2 per utenti Symfony 1.x: Architettura, modelli ed esempi
Symfony2  per utenti Symfony 1.x: Architettura, modelli ed esempiSymfony2  per utenti Symfony 1.x: Architettura, modelli ed esempi
Symfony2 per utenti Symfony 1.x: Architettura, modelli ed esempi
Filippo De Santis
 

En vedette (20)

Project Slide Show
Project Slide ShowProject Slide Show
Project Slide Show
 
How we build caibangzi.com
How we build caibangzi.comHow we build caibangzi.com
How we build caibangzi.com
 
Домен .tel - новый способ коммуникации
Домен .tel - новый способ коммуникацииДомен .tel - новый способ коммуникации
Домен .tel - новый способ коммуникации
 
Professional Work
Professional WorkProfessional Work
Professional Work
 
Хостеры и регистраторы - операторы персональных данных
Хостеры и регистраторы - операторы персональных данныхХостеры и регистраторы - операторы персональных данных
Хостеры и регистраторы - операторы персональных данных
 
Greytower identity Overview
Greytower identity  OverviewGreytower identity  Overview
Greytower identity Overview
 
Grey tower and NetIQ - Identity Manager Integration with MuleSoft ESB
Grey tower and NetIQ - Identity Manager Integration with MuleSoft ESBGrey tower and NetIQ - Identity Manager Integration with MuleSoft ESB
Grey tower and NetIQ - Identity Manager Integration with MuleSoft ESB
 
Technologypowerpoint
TechnologypowerpointTechnologypowerpoint
Technologypowerpoint
 
Ruby On Rails Pitfalls
Ruby On Rails PitfallsRuby On Rails Pitfalls
Ruby On Rails Pitfalls
 
High quality iOS development
High quality iOS developmentHigh quality iOS development
High quality iOS development
 
Cocoa Design Patterns
Cocoa Design PatternsCocoa Design Patterns
Cocoa Design Patterns
 
Orient Advertising, Profile
Orient Advertising, ProfileOrient Advertising, Profile
Orient Advertising, Profile
 
Khi internation food fest 2012 - for media partner
Khi internation food fest   2012 - for media partnerKhi internation food fest   2012 - for media partner
Khi internation food fest 2012 - for media partner
 
Orient Advertising - Profile
Orient Advertising - ProfileOrient Advertising - Profile
Orient Advertising - Profile
 
Gastcollege CHE
Gastcollege CHEGastcollege CHE
Gastcollege CHE
 
Symfony2 per utenti Symfony 1.x: Architettura, modelli ed esempi
Symfony2  per utenti Symfony 1.x: Architettura, modelli ed esempiSymfony2  per utenti Symfony 1.x: Architettura, modelli ed esempi
Symfony2 per utenti Symfony 1.x: Architettura, modelli ed esempi
 
Grey tower technical capablities
Grey tower  technical capablitiesGrey tower  technical capablities
Grey tower technical capablities
 
Suggestions and Ideas for DigitalOcean
Suggestions and Ideas for DigitalOceanSuggestions and Ideas for DigitalOcean
Suggestions and Ideas for DigitalOcean
 
Arquitectura I Escultura Grega
Arquitectura I Escultura GregaArquitectura I Escultura Grega
Arquitectura I Escultura Grega
 
Digitaalinen turvallisuus muuttuvassa ympäristössä
Digitaalinen turvallisuus muuttuvassa ympäristössäDigitaalinen turvallisuus muuttuvassa ympäristössä
Digitaalinen turvallisuus muuttuvassa ympäristössä
 

Similaire à Blocks & Grand Central Dispatch

Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
NAVER D2
 
GraalVMの紹介とTruffleでPHPぽい言語を実装したら爆速だった話
GraalVMの紹介とTruffleでPHPぽい言語を実装したら爆速だった話GraalVMの紹介とTruffleでPHPぽい言語を実装したら爆速だった話
GraalVMの紹介とTruffleでPHPぽい言語を実装したら爆速だった話
なおき きしだ
 

Similaire à Blocks & Grand Central Dispatch (20)

Android OpenGL ES Game ImageGrabber Final Report
Android OpenGL ES Game ImageGrabber Final ReportAndroid OpenGL ES Game ImageGrabber Final Report
Android OpenGL ES Game ImageGrabber Final Report
 
Kandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_finalKandroid for nhn_deview_20131013_v5_final
Kandroid for nhn_deview_20131013_v5_final
 
The Twelve Factor App - Pivotal Tracker
The Twelve Factor App - Pivotal TrackerThe Twelve Factor App - Pivotal Tracker
The Twelve Factor App - Pivotal Tracker
 
Kgdb kdb modesetting
Kgdb kdb modesettingKgdb kdb modesetting
Kgdb kdb modesetting
 
Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel Bugs
 
DWX 2018 - Automatisiertes Datenbank-Deployment im DevOps Prozess
DWX 2018 - Automatisiertes Datenbank-Deployment im DevOps ProzessDWX 2018 - Automatisiertes Datenbank-Deployment im DevOps Prozess
DWX 2018 - Automatisiertes Datenbank-Deployment im DevOps Prozess
 
DWX 2018 - Automatisiertes Datenbankdeployment im DevOps Prozess
DWX 2018 - Automatisiertes Datenbankdeployment im DevOps ProzessDWX 2018 - Automatisiertes Datenbankdeployment im DevOps Prozess
DWX 2018 - Automatisiertes Datenbankdeployment im DevOps Prozess
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS Projects
 
CeedMath & CeedGL, Let's talk 3D...
CeedMath & CeedGL, Let's talk 3D...CeedMath & CeedGL, Let's talk 3D...
CeedMath & CeedGL, Let's talk 3D...
 
MongoDB开发应用实践
MongoDB开发应用实践MongoDB开发应用实践
MongoDB开发应用实践
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the Cloud
 
Practical Git - NYC Code Camp
Practical Git - NYC Code CampPractical Git - NYC Code Camp
Practical Git - NYC Code Camp
 
Command box, Package Manager, Automation, REPL
Command box, Package Manager, Automation, REPLCommand box, Package Manager, Automation, REPL
Command box, Package Manager, Automation, REPL
 
2014 11-05 hpcac-kniep_christian_dockermpi
2014 11-05 hpcac-kniep_christian_dockermpi2014 11-05 hpcac-kniep_christian_dockermpi
2014 11-05 hpcac-kniep_christian_dockermpi
 
Practical Git - Philly.NET Code Camp
Practical Git - Philly.NET Code CampPractical Git - Philly.NET Code Camp
Practical Git - Philly.NET Code Camp
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
 
GraalVMの紹介とTruffleでPHPぽい言語を実装したら爆速だった話
GraalVMの紹介とTruffleでPHPぽい言語を実装したら爆速だった話GraalVMの紹介とTruffleでPHPぽい言語を実装したら爆速だった話
GraalVMの紹介とTruffleでPHPぽい言語を実装したら爆速だった話
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)
 
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
 
Learn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levelsLearn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levels
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Blocks & Grand Central Dispatch

Notes de l'éditeur

  1. \n
  2. Blocks和GCD作为Objective-C和Cocoa的特性,最早在Mac OS X 10.6 Snow Leopard引入。iPhone从iOS 4开始支持。主要用于解决异步问题。\n
  3. Blocks类似Lamdba演算和closure,是一段函数体,可以作为对象传递,又能保留其词法作用域。\n\n大量运用于函数式语言和很多动态语言中,比如Lisp, SmallTalk和Ruby。和Ruby中对此类对象的称呼相同。\nBlocks是Apple为C/C++/Objective-C提供的非标准扩展。在GCC和Clang LLVM中分别实现。\n\n将函数的某一部分以另一种方式执行。比如异步执行,或者在另一个作用域中执行。\n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. 线程开发相对复杂。开多少线程合适?线程调度和管理。线程执行的顺序。竞争机制。\nGCD利用队列分发的方式,提供了比较透明的线程管理,简单易用。开发者不用考虑到底要开多少线程。\n
  10. \n
  11. 开发者向queue中加入Task,无需知道到底分配了多少线程。\ntask以先进先出的方式执行,系统自行管理线程。线程所占用的内存是系统层而不是应用层的。\n这是一个并发队列。 如果是一个串行队列,一次只执行一个task,可以保证task的执行顺序,无需使用锁机制。\n
  12. \n
  13. \n
  14. Main dispatch queue是一个全局串行队列,在应用的主run loop中。\n
  15. \n
  16. 串行队列,一个队列每次只执行一个task,可以创建多个队列,不同队列之间并发运行。如果task需要同步访问某一个资源,可以采用串行队列来解决同步问题,而不用加锁。\n\n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n