100% found this document useful (3 votes)
114 views

Immediate download Concurrency by Tutorials Second Edition Multithreading in Swift with GCD and Operations Tutorial Team ebooks 2024

Second

Uploaded by

marekreccakv
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
114 views

Immediate download Concurrency by Tutorials Second Edition Multithreading in Swift with GCD and Operations Tutorial Team ebooks 2024

Second

Uploaded by

marekreccakv
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Concurrency by Tutorials Second Edition


Multithreading in Swift with GCD and Operations
Tutorial Team

https://textbookfull.com/product/concurrency-by-tutorials-
second-edition-multithreading-in-swift-with-gcd-and-
operations-tutorial-team/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Design Patterns by Tutorials Third Edition Learning Design


Patterns in Swift Raywenderlich Tutorial Team

https://textbookfull.com/product/design-patterns-by-tutorials-third-
edition-learning-design-patterns-in-swift-raywenderlich-tutorial-team/

textboxfull.com

iOS 11 by Tutorials Learning the new iOS APIs with Swift 4


1st Edition The Raywenderlich Tutorial Team

https://textbookfull.com/product/ios-11-by-tutorials-learning-the-new-
ios-apis-with-swift-4-1st-edition-the-raywenderlich-tutorial-team/

textboxfull.com

RxSwift Reactive Programming with Swift Third Edition


Raywenderlich Tutorial Team

https://textbookfull.com/product/rxswift-reactive-programming-with-
swift-third-edition-raywenderlich-tutorial-team/

textboxfull.com

Server Side Swift with Vapor Building Web APIs and Web
Apps in Swift 3rd Edition Raywenderlich.Com Tutorial Team

https://textbookfull.com/product/server-side-swift-with-vapor-
building-web-apis-and-web-apps-in-swift-3rd-edition-raywenderlich-com-
tutorial-team/
textboxfull.com
Machine Learning by Tutorials Beginning Machine Learning
for Apple and iOS First Edition Raywenderlich Tutorial
Team
https://textbookfull.com/product/machine-learning-by-tutorials-
beginning-machine-learning-for-apple-and-ios-first-edition-
raywenderlich-tutorial-team/
textboxfull.com

iOS Apprentice Eighth Edition Beginning iOS Development


with Swift and UIKit Raywenderlich Tutorial Team

https://textbookfull.com/product/ios-apprentice-eighth-edition-
beginning-ios-development-with-swift-and-uikit-raywenderlich-tutorial-
team/
textboxfull.com

Design Patterns by Tutorials Learning design patterns in


Swift 4 2 Joshua Greene

https://textbookfull.com/product/design-patterns-by-tutorials-
learning-design-patterns-in-swift-4-2-joshua-greene/

textboxfull.com

Core Data By Tutorials Aaron Douglas

https://textbookfull.com/product/core-data-by-tutorials-aaron-douglas/

textboxfull.com

Simulations in Swift 5: Design and Implement with Swift


Playgrounds Beau Nouvelle

https://textbookfull.com/product/simulations-in-swift-5-design-and-
implement-with-swift-playgrounds-beau-nouvelle/

textboxfull.com
Concurrency by Tutorials

Concurrency by Tutorials
By Scott Grosch

Copyright ©2019 Razeware LLC.

Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text,
images, or source code) may be reproduced or distributed by any means without prior
written permission of the copyright owner.

Notice of Liability
This book and all corresponding materials (such as source code) are provided on an
“as is” basis, without warranty of any kind, express of implied, including but not
limited to the warranties of merchantability, fitness for a particular purpose, and
noninfringement. In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use of other dealing in
the software.

Trademarks
All trademarks and registered trademarks appearing in this book are the property of
their own respective owners.

raywenderlich.com 2
Concurrency by Tutorials

Table of Contents: Overview


About the Cover ......................................................................................... 8
Acknowledgements ............................................................................... 12
What You Need ........................................................................................ 13
Book License ............................................................................................. 14
Book Source Code & Forums ............................................................. 15
Section I: Getting Started with Concurrency ............ 17
Chapter 1: Introduction ........................................................... 18
Chapter 2: GCD & Operations .............................................. 21
Section II: Grand Central Dispatch ............................... 27
Chapter 3: Queues & Threads ............................................... 28
Chapter 4: Groups & Semaphores ....................................... 40
Chapter 5: Concurrency Problems ...................................... 49
Section III: Operations ...................................................... 57
Chapter 6: Operations .............................................................. 58
Chapter 7: Operation Queues ............................................... 69
Chapter 8: Asynchronous Operations ............................... 76
Chapter 9: Operation Dependencies.................................. 87
Chapter 10: Canceling Operations ...................................... 97
Section IV: Real-Life Concurrency ............................. 103
Chapter 11: Core Data .......................................................... 104
Chapter 12: Thread Sanitizer .............................................. 110

raywenderlich.com 3
Concurrency by Tutorials

Conclusion .............................................................................................. 115

raywenderlich.com 4
Concurrency by Tutorials

Table of Contents: Extended


About the Cover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
About the Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
About the Artist. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
What You Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Book License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Book Source Code & Forums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Section I: Getting Started with Concurrency . . . . . . . 17
Chapter 1: Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
What is concurrency? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Why use concurrency? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
How to use concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Chapter 2: GCD & Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Grand Central Dispatch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Which should you use? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Section II: Grand Central Dispatch . . . . . . . . . . . . . . . . . 27


Chapter 3: Queues & Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Dispatch queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Image loading example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
DispatchWorkItem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

raywenderlich.com 5
Concurrency by Tutorials

Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39


Chapter 4: Groups & Semaphores . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
DispatchGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Semaphores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Chapter 5: Concurrency Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Race conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Deadlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Priority inversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

Section III: Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57


Chapter 6: Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Reusability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Operation states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
BlockOperation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Subclassing operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Chapter 7: Operation Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
OperationQueue management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Fix the previous project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Chapter 8: Asynchronous Operations . . . . . . . . . . . . . . . . . . . . . . . 76
Asynchronous operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Networked TiltShift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Chapter 9: Operation Dependencies . . . . . . . . . . . . . . . . . . . . . . . . 87
Modular design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Specifying dependencies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Watch out for deadlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Passing data between operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

raywenderlich.com 6
Concurrency by Tutorials

Updating the table view controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93


Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Chapter 10: Canceling Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 97
The magic of cancel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Cancel and cancelAllOperations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Updating AsyncOperation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Canceling a running operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Section IV: Real-Life Concurrency . . . . . . . . . . . . . . . . 103


Chapter 11: Core Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
NSManagedObjectContext is not thread safe . . . . . . . . . . . . . . . . . . . . . . 105
Importing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
NSAsynchronousFetchRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Sharing an NSManagedObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Chapter 12: Thread Sanitizer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Why the sanitizer? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Enabling sanitization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
It’s not code analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Xcode keeps getting smarter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

raywenderlich.com 7
A About the Cover

Our usual experience when looking at an animal is to see the creature and know,
clearly, how its body is assigned and what each of its parts does — two legs for
walking, two ears for hearing, a mouth for eating, gills for breathing, one brain for
thinking.

In looking at a starfish, however, things get a little trickier.

Everything about the starfish is in multitudes that aren't always obvious to our eye:
five–50 arms, a mouth with five jaws, a eyespot on each arm with 80–100 ocelli, a
decentralized respiratory and central nervous system, a three-ringed circulatory
system, a common “mouth” used both in consuming and excreting, and tubed “feet”
that assist with sensing, moving and breathing.

These marine invertebrates, including the Royal Starfish (Astropecten articulatus)


that is found on the cover of this book, operate in the spirit of concurrency, having
adapted so that the parts of their bodies have multiple functions — feet that help it
move, feel, see and breathe, for example — for a simple but optimal life.

Because of their adaptability and optimization of function, seastars are considered


ecologically important as they, like the operations in this book, help their
environment to be cleaner and more efficient.

If you find yourself on the east coast of the continental Americas, especially the
Caribbean, keep an eye out for a relatively small, impossibly purple seastar with
brilliant orange edges.

Learn more about the Royal Starfish, here: https://en.wikipedia.org/wiki/


Astropecten_articulatus.

raywenderlich.com 8
Concurrency by Tutorials About the Cover

Dedications
"This book is dedicated to my wife and daughter, as well as to
my parents who always made sure a good education was a
priority."

— Scott Grosch

raywenderlich.com 9
Concurrency by Tutorials About the Cover

About the Author


Scott Grosch is the author of this book. He has been involved with
iOS app development since the first release of the public SDK from
Apple. He mostly works with a small set of clients on a couple large
apps. During the day, Scott is a Solutions Architect at a Fortune 500
company in the Pacific Northwest. At night, he's still working on
figuring out how to be a good parent to a toddler with his wife.

About the Editors


Marin Bencevic is the tech editor of this book. He is a Swift and
Unity developer who likes to work on cool iOS apps and games,
nerd out about programming, learn new things and then blog
about it. Mostly, though, he just causes SourceKit crashes. He also
has a chubby cat.

Shai Mishali is the Final Pass Editor of this book. He's the iOS
Tech Lead for Gett, the global on-demand mobility company; as
well as an international speaker, and a highly active open-source
contributor and maintainer on several high-profile projects -
namely, the RxSwift Community and RxSwift projects. As an avid
enthusiast of hackathons, Shai took 1st place at BattleHack Tel-
Aviv 2014, BattleHack World Finals San Jose 2014, and Ford's
Developer Challenge Tel-Aviv 2015. You can find him on GitHub
and Twitter @freak4pc.

Manda Frederick is the editor of this book. She has been involved
in publishing for over 10 years through various creative,
educational, medical and technical print and digital publications,
and is thrilled to bring her experience to the raywenderlich.com
family as Managing Editor. In her free time, you can find her at the
climbing gym, backpacking in the backcountry, hanging with her
dog, working on poems, playing guitar and exploring breweries.

raywenderlich.com 10
Concurrency by Tutorials About the Cover

About the Artist


Vicki Wenderlich is the designer and artist of the cover of this
book. She is Ray’s wife and business partner. She is a digital artist
who creates illustrations, game art and a lot of other art or design
work for the tutorials and books on raywenderlich.com. When she’s
not making art, she loves hiking, a good glass of wine and
attempting to create the perfect cheese plate.

raywenderlich.com 11
A Acknowledgements

We'd like to thank:

Luke Freeman for coordinating and/or creating many of the images that you see in
this book.

Amy Sawatzky for her editorial assistance to the author.

raywenderlich.com 12
W What You Need

To follow along with this book, you’ll need the following:

• A Mac running macOS Mojave (10.14) or later. Earlier versions might work, but
they're untested.

• Xcode 11 or later. Xcode is the main development tool for iOS. While earlier
versions of Xcode should work, the examples in this book have been specifically
tested on Xcode 11 and iOS 13. You can download the latest version of Xcode from
Apple’s developer site here: apple.co/2asi58y

• An intermediate level knowledge of Swift. This book teaches concurrency when


building iOS applications using Swift. You could use the knowledge acquired in
this book for your Objective-C codebase, but this book won’t include any
Objective-C examples. You could also use this knowledge for your macOS, tvOS
and watchOS apps, but like Objective-C, this book won’t include any examples for
these platforms.

If you want to try things out on a physical iOS device, you’ll need a developer
account with Apple, which you can obtain for free. However, all the sample projects
in this book will work just fine in the iOS Simulator bundled with Xcode, so the paid
developer account is completely optional.

raywenderlich.com 13
L Book License

By purchasing Concurrency by Tutorials, you have the following license:

• You are allowed to use and/or modify the source code in Concurrency by Tutorials in
as many apps as you want, with no attribution required.

• You are allowed to use and/or modify all art, images and designs that are included
in Concurrency by Tutorials in as many apps as you want, but must include this
attribution line somewhere inside your app: “Artwork/images/designs: from
Concurrency by Tutorials, available at www.raywenderlich.com”.

• The source code included in Concurrency by Tutorials is for your personal use only.
You are NOT allowed to distribute or sell the source code in Concurrency by
Tutorials without prior authorization.

• This book is for your personal use only. You are NOT allowed to sell this book
without prior authorization, or distribute it to friends, coworkers or students; they
would need to purchase their own copies.

All materials provided with this book are provided on an “as is” basis, without
warranty of any kind, express or implied, including but not limited to the warranties
of merchantability, fitness for a particular purpose and noninfringement. In no event
shall the authors or copyright holders be liable for any claim, damages or other
liability, whether in an action or contract, tort or otherwise, arising from, out of or in
connection with the software or the use or other dealings in the software.

All trademarks and registered trademarks appearing in this guide are the properties
of their respective owners.

raywenderlich.com 14
B Book Source Code &
Forums

If you bought the digital edition


The digital edition of this book comes with the source code for the starter and
completed projects for each chapter. These resources are included with the digital
edition you downloaded from store.raywenderlich.com.

The digital edition of this book also comes with free access to any future updates we
may make to the book!

The best way to get update notifications is to sign up for our monthly newsletter.
This includes a list of the tutorials that came out on raywenderlich.com that month,
any important news like book updates or new books, and a list of our favorite iOS
development links for that month. You can sign up here:

• www.raywenderlich.com/newsletter

If you bought the print version


You can get the source code for the print edition of the book here:

https://store.raywenderlich.com/products/concurrency-by-tutorials-source-code

Forums
We’ve also set up an official forum for the book at forums.raywenderlich.com. This is
a great place to ask questions about the book or to submit any errors you may find.

raywenderlich.com 15
Concurrency by Tutorials Book Source Code & Forums

Digital book editions


We have a digital edition of this book available in both ePUB and PDF, which can be
handy if you want a soft copy to take with you, or you want to quickly search for a
specific term within the book.

Buying the digital edition version of the book also has a few extra benefits: free
updates each time we update the book, access to older versions of the book, and you
can download the digital editions from anywhere, at anytime.

Visit our book store page here:

• https://store.raywenderlich.com/products/concurrency-by-tutorials.

And if you purchased the print version of this book, you’re eligible to upgrade to the
digital editions at a significant discount! Simply email [email protected] with
your receipt for the physical copy and we’ll get you set up with the discounted digital
edition version of the book.

raywenderlich.com 16
Section I: Getting Started with
Concurrency

In this part of the book, you’re going to learn about the basics of Concurrency. You're
going to learn what it is, what kind of problems it solves, and why would you even
use it?

Further, you will learn the basic pieces of which Concurrency comprises in iOS
development: Grand Central Dispatch and Operations.

This section will provide you with the foundational knowledge regarding
Concurrency, so be sure to read through! The upcoming sections will dive much
deeper into each of these concepts individually.

Chapter 1: Introduction: Get a quick overview of what concurrency is and why you
might want to use it.

Chapter 2: GCD vs. Operations: GCD vs.Operations: Concurrency can be handled


by either Grand Central Dispatch (GCD) or Operations. Learn about the differences
between the two and why you might choose one over the other.

raywenderlich.com 17
1 Chapter 1: Introduction

Performance. Responsiveness. They’re not sexy tasks. When done properly, nobody is
going to thank you. When done incorrectly, app retention is going to suffer and you’ll
be dinged during your next yearly performance review.

There are a multitude of ways in which an app can be optimized for speed,
performance and overall responsiveness. This book will focus on the topic of
concurrency.

What is concurrency?
Wikipedia defines concurrency as "the decomposability property of a program,
algorithm, or problem into order-independent or partially-ordered components or
units." What this means is looking at the logic of your app to determine which pieces
can run at the same time, and possibly in a random order, yet still result in a correct
implementation of your data flow.

Moderns devices almost always have more than a single CPU, and Apple’s iPhones
have been dual core since 2011. Having more than one core means they are capable
of running more than a single task at the same time. By splitting your app into
logical "chunks" of code you enable the iOS device to run multiple parts of your
program at the same time, thus improving overall performance.

raywenderlich.com 18
Concurrency by Tutorials Chapter 1: Introduction

Why use concurrency?


It’s critical to ensure that your app runs as smoothly as possible and that the end
user is not ever forced to wait for something to happen. A second is a minuscule
amount of time for most everything not related to a computer. However, if a human
has to wait a second to see a response after taking an action on a device like an
iPhone, it feels like an eternity. "It’s too slow" is one of the main contributors to your
app being uninstalled.

Scrolling through a table of images is one of the more common situations wherein
the end user will be impacted by the lack of concurrency. If you need to download an
image from the network, or perform some type of image processing before displaying
it, the scrolling will stutter and you’ll be forced to display multiple "busy" indicators
instead of the expected image.

A beneficial side effect to using concurrency is that it helps you to spend a bit more
time thinking about your app’s overall architecture. Instead of just writing massive
methods to "get the job done" you’ll find yourself naturally writing smaller, more
manageable methods that can run concurrently.

How to use concurrency


That’s the focus of this book! At a high level you need to structure your app so that
some tasks can run at the same time. Multiple tasks that modify the same resource
(i.e., variable) can’t run at the same time, unless you make them thread safe.

Tasks which access different resources, or read-only shared resources, can all be
accessed via different threads to allow for much faster processing.

This book will focus on the two main ways that iOS provides you with the ability to
run code concurrently. The first section on Grand Central Dispatch will cover the
common scenarios where you will find yourself being able to implement concurrency.
You’ll learn how to run tasks in the background, how to group tasks together and
how to handle restricting the number of tasks that can run at once. By the end of the
first section you’ll also have a strong grasp of the dangers of concurrency and how to
avoid them.

In the second section you’ll focus on the Operation class. Built on top of Grand
Central Dispatch, operations allow for the handling of more complex scenarios such
as reusable code to be run on a background thread, having one thread depend on
another, and even canceling an operation before it’s started or completed.

raywenderlich.com 19
Concurrency by Tutorials Chapter 1: Introduction

Most modern programming languages provide for some form of concurrency and
Swift is of course no exception. Different languages use widely different mechanisms
for handling concurrency. C# and Typescript, for example use an async/await pattern,
whereas Swift uses closures to handle what runs on another thread. Swift 5 originally
had plans to implement the more common async/await pattern but it was removed
from the specification until the next release.

Where to go from here?


Well to the next page of course! Hopefully as you work through the following
chapters you’ll gain an appreciation for what concurrency can do for your app and
why your end users will appreciate the extra effort you put into making the app
perform as fast as possible. Knowing when to use Grand Central Dispatch as opposed
to an Operation subclass early in the app lifecycle will save you hours of rework
down the road.

raywenderlich.com 20
2 Chapter 2: GCD &
Operations

There are two APIs that you'll use when making your app concurrent: Grand Central
Dispatch, commonly referred to as GCD, and Operations. These are neither
competing technologies nor something that you have to exclusively pick between. In
fact, Operations are built on top of GCD!

raywenderlich.com 21
Concurrency by Tutorials Chapter 2: GCD & Operations

Grand Central Dispatch


GCD is Apple’s implementation of C’s libdispatch library. Its purpose is to queue up
tasks — either a method or a closure — that can be run in parallel, depending on
availability of resources; it then executes the tasks on an available processor core.

Note: Apple’s documentation sometimes refers to a block in lieu of closure,


since that was the name used in Objective-C. You can consider them
interchangeable in the context of concurrency.

While GCD uses threads in its implementation, you, as the developer, do not need to
worry about managing them yourself. GCD’s tasks are so lightweight to enqueue that
Apple, in its 2009 technical brief on GCD, stated that only 15 instructions are
required for implementation, whereas creating traditional threads could require
several hundred instructions.

All of the tasks that GCD manages for you are placed into GCD-managed first-in,
first-out (FIFO) queues. Each task that you submit to a queue is then executed
against a pool of threads fully managed by the system.

Note: There is no guarantee as to which thread your task will execute against.

Synchronous and asynchronous tasks


Work placed into the queue may either run synchronously or asynchronously.
When running a task synchronously, your app will wait and block the current run
loop until execution finishes before moving on to the next task. Alternatively, a task
that is run asynchronously will start, but return execution to your app immediately.
This way, the app is free to run other tasks while the first one is executing.

Note: It’s important to keep in mind that, while the queues are FIFO based,
that does not ensure that tasks will finish in the order you submit them. The
FIFO procedure applies to when the task starts, not when it finishes.

raywenderlich.com 22
Concurrency by Tutorials Chapter 2: GCD & Operations

In general, you'll want to take any long-running non-UI task that you can find and
make it run asynchronously in the background. GCD makes this very simple via
closures with a few lines of code, like so:

// Class level variable


let queue = DispatchQueue(label: "com.raywenderlich.worker")

// Somewhere in your function


queue.async {
// Call slow non-UI methods here

DispatchQueue.main.async {
// Update the UI here
}
}

You'll learn all about DispatchQueue in Chapter 3, "Queues & Threads." In general,
you create a queue, submit a task to it to run asynchronously on a background
thread, and, when it’s complete, you delegate the code back to the main thread to
update the UI.

Serial and concurrent queues


The queue to which your task is submitted also has a characteristic of being either
serial or concurrent. Serial queues only have a single thread associated with them
and thus only allow a single task to be executed at any given time. A concurrent
queue, on the other hand, is able to utilize as many threads as the system has
resources for. Threads will be created and released as necessary on a concurrent
queue.

Note: While you can tell iOS that you'd like to use a concurrent queue,
remember that there is no guarantee that more than one task will run at a
time. If your iOS device is completely bogged down and your app is competing
for resources, it may only be capable of running a single task.

Asynchronous doesn’t mean concurrent


While the difference seems subtle at first, just because your tasks are asynchronous
doesn’t mean they will run concurrently. You’re actually able to submit asynchronous
tasks to either a serial queue or a concurrent queue. Being synchronous or
asynchronous simply identifies whether or not the queue on which you’re running
the task must wait for the task to complete before it can spawn the next task.

raywenderlich.com 23
Concurrency by Tutorials Chapter 2: GCD & Operations

On the other hand, categorizing something as serial versus concurrent identifies


whether the queue has a single thread or multiple threads available to it. If you think
about it, submitting three asynchronous tasks to a serial queue means that each task
has to completely finish before the next task is able to start as there is only one
thread available.

In other words, a task being synchronous or not speaks to the source of the task.
Being serial or concurrent speaks to the destination of the task.

Operations
GCD is great for common tasks that need to be run a single time in the background.
When you find yourself building functionality that should be reusable — such as
image editing operations — you will likely want to encapsulate that functionality
into a class. By subclassing Operation, you can accomplish that goal!

Operation subclassing
Operations are fully-functional classes that can be submitted to an
OperationQueue, just like you'd submit a closure of work to a DispatchQueue for
GCD. Because they’re classes and can contain variables, you gain the ability to know
what state the operation is in at any given point.

Operations can exist in any of the following states:

• isReady
• isExecuting
• isCancelled
• isFinished
Unlike GCD, an operation is run synchronously by default, and getting it to run
asynchronously requires more work. While you can directly execute an operation
yourself, that’s almost never going to be a good idea due to its synchronous nature.
You'll want to get it off of the main thread by submitting it to an OperationQueue so
that your UI performance isn’t impacted.

Bonus features
But wait, there’s more! Operations provide greater control over your tasks as you can
now handle such common needs as cancelling the task, reporting the state of the

raywenderlich.com 24
Concurrency by Tutorials Chapter 2: GCD & Operations

task, wrapping asynchronous tasks into an operation and specifying dependences


between various tasks. Chapter 6, "Operations," will provide a more in-depth
discussion of using operations in your app.

BlockOperation
Sometimes, you find yourself working on an app that heavily uses operations, but
find that you have a need for a simpler, GCD-like, closure. If you don’t want to also
create a DispatchQueue, then you can instead utilize the BlockOperation class.

BlockOperation subclasses Operation for you and manages the concurrent


execution of one or more closures on the default global queue. However, being an
actual Operation subclass lets you take advantage of all the other features of an
operation.

Note: Block operations run concurrently. If you need them to run serially,
you'll need to setup a dispatch queue instead.

Which should you use?


There’s no clear-cut directive as to whether you should use GCD or Operations in
your app. GCD tends to be simpler to work with for simple tasks you just need to
execute and forget. Operations provide much more functionality when you need to
keep track of a job or maintain the ability to cancel it.

If you’re just working with methods or chunks of code that need to be executed, GCD
is a fitting choice. If you’re working with objects that need to encapsulate data and
functionality then you’re more likely to utilize Operations. Some developers even go
to the extreme of saying that you should always use Operations because it’s built on
top of GCD, and Apple’s guidance says to always use the highest level of abstraction
provided.

At the end of the day, you should use whichever technology makes the most sense at
the time and provides for the greatest long-term sustainability of your project, or
specific use-case.

In the next chapter, you'll take a deep dive into how Grand Central Dispatch works,
learn about the difference between threads and queues, and identify some of the
complexities that can occur when implementing concurrency in your app.

raywenderlich.com 25
Concurrency by Tutorials Chapter 2: GCD & Operations

Where to go from here?


To the next chapter, of course! The rest of the book will examine, in detail, both
Grand Central Dispatch and Operations. By the time you’ve completed the book
you'll have a solid grasp on what both options provide, as well as a better idea on how
to choose one over the other.

raywenderlich.com 26
Section II: Grand Central
Dispatch

In this section, you'll take a deep dive into Apple's most popular and easy-to-use
mechanism to write and manage concurrent tasks — Grand Central Dispatch. You'll
learn how to utilize queues and threads to control the execution of tasks in your app,
as well as how to group these tasks together. You'll also learn about common pitfalls
and dangers of using concurrency, and how you can avoid them.

Chapter 3: Queues & Threads: This chapter teaches you how to use a GCD queue
to offload work from the main thread. You'll also learn what a "thread" is.

Chapter 4: Groups & Semaphores: In the previous chapter you learned about how
queues work. In this chapter you'll expand that knowledge to learn how to submit
multiple tasks to a queue, which need to run together as a "group" so that you can be
notified when they have all completed. You'll also learn how to wrap an existing API
so that you can call it asynchronously.

Chapter 5: Concurrency Problems: By now you know how GCD can make your app
so much faster. This chapter will show you some of the dangers of concurrency if
you're not careful, and how to avoid them.

raywenderlich.com 27
3 Chapter 3: Queues &
Threads

Dispatch queues and threads have been mentioned a couple of times now, and you’re
probably wondering what they are at this point. In this chapter, you’ll get a much
deeper understanding of what Dispatch queue and Threads are, and how to best
incorporate them in your development workflow.

raywenderlich.com 28
Concurrency by Tutorials Chapter 3: Queues & Threads

Threads
You’ve probably heard the term multithreading at some point, yes? A thread is
really short for thread of execution, and it’s how a running process splits tasks
across resources on the system. Your iOS app is a process that runs multiple tasks by
utilizing multiple threads. You can have as many threads executing at once as you
have cores in your device’s CPU.

There are many advantages to splitting your app’s work into multiple threads:

• Faster execution: By running tasks on threads, it’s possible for work to be done
concurrently, which will allow it to finish faster than running everything serially.

• Responsiveness: If you only perform user-visible work on the main UI thread,


then users won’t notice that the app slows down or freezes up periodically due to
work that could be performed on another thread.

• Optimized resource consumption: Threads are highly optimized by the OS.

Sounds great, right? More cores, more threads, faster app. I bet you’re ready to learn
how to create one, right? Too bad! In reality, you should never find yourself needing
to create a thread explicitly. The OS will handle all thread creation for you using
higher abstractions.

Apple provides the APIs necessary for thread management, but if you try to directly
manage them yourself, you could in fact degrade, rather than improve, performance.
The OS keeps track of many statistics to know when it should and should not allocate
or destroy threads. Don’t fool yourself into thinking it’s as simple as spinning up a
thread when you want one. For those reasons, this book will not cover direct thread
management.

Dispatch queues
The way you work with threads is by creating a DispatchQueue. When you create a
queue, the OS will potentially create and assign one or more threads to the queue. If
existing threads are available, they can be reused; if not, then the OS will create
them as necessary.

raywenderlich.com 29
Another Random Scribd Document
with Unrelated Content
THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it
away or re-use it under the terms of the Project Gutenberg
License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country where
you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of the
copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute
this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite
these efforts, Project Gutenberg™ electronic works, and the
medium on which they may be stored, may contain “Defects,”
such as, but not limited to, incomplete, inaccurate or corrupt
data, transcription errors, a copyright or other intellectual
property infringement, a defective or damaged disk or other
medium, a computer virus, or computer codes that damage or
cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES -


Except for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU
AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE,
STRICT LIABILITY, BREACH OF WARRANTY OR BREACH
OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE
TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER
THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR
ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE
OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF
THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If


you discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person or
entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you do
or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status by
the Internal Revenue Service. The Foundation’s EIN or federal
tax identification number is 64-6221541. Contributions to the
Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or
determine the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like