SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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ä
 

Ähnlich wie 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ぽい言語を実装したら爆速だった話
なおき きしだ
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Blocks & Grand Central Dispatch

Hinweis der Redaktion

  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