Tip:
Highlight text to annotate it
X
grand central dispatch *** cd was a new feature with higher risk for and if you
read the official documentation from an awful about it
you'll see a lot of phrases like provide systemic comprehensive improvements in
the support for concurrent code execution
well the end of the day we want grand central dispatch because it makes
multi threading easy
your question right back on this might be or why do we care of the multi
threading is easy
amid result no matter how you spend it
is we want to have a more responsive user interface in application we want
our dance to feel more professional we want them to be able to do multiple
things at once
thank you were talking about
multi threading not multitasking
multitasking which we have
is the idea of multiple applications at the same time
and as we've seen i was handles switching different applications between
background and foreground states the were talking about multi threading
missus jesper aap
the ability for our application to do multiple things at the same time
and he still might be thinking well
why is this important
and the issue is that we can have a problem with the idea of arnab
one q for processing we have this main key role in the performs tasks
one after the other strictly an order whether it's updating the yuan
performing calculations connecting to a database whatever weekend with g c d
creepy custom q
and take some of these tasks on
make them run on their onkyo
and grand central dispatch in iowa's will take care of all of this making
sure it happens responsibly and happen smoothly
and the key benefit here is particularly the ability to make sure our user
interface stays responsive
even while heavy processing goes on in the background
so how do we use and work with grand central dispatch in our eyelash
applications
there are two steps
step one you create a new q will see this in a moment
we give the same name whatever name is meaningful for us disc you might be just
for networking or just for long-running calculations
then step to you create blocks that we've just talked about and you drop
them in the queue that step two
step three is nothing that's it
okay so there is a little bit more when you get into advanced parts of this but
for most people most of the time
the whole process
of using grand central dispatch is
making it to you in your application add blocks to the q let bio s take care of
everything else
and if you're someone who's programmed multi threaded code before
you'll know that it's a fairly unpleasant thing to do
grand central dispatch doesn't just make multi threaded correct easier it makes
it easy
most of the time we're going to be interested in to main commands that
we're going to execute
is to create a new q
and it's this function dispatch underscore q underscore create
and the way that we use it as like this to crate of variable in this case have
called it mike you and i give it allay boldest to string that's pretty much it
has that mike you name this could be a descriptive label for the skiers being
used for the reason we give it a label as if we want to see it and debugging
information later on
when i show you an example in a moment i'll show you that the typical label we
put in here has actually reversed d_m_s_ notation but you can put any text in his
meaningful for you
so we've created a cute i've now got a q variable called my cube and then i'm
going to use the other most important command in grand central dispatch
which is dispatch underscores a cent
and the simply takes to parameters the name of the q
there were dispatching to
on a block
i can see the catch here
with the curly braces they contain my block everything that we want to do a
synchronously which in this case is just passing in one message one called to
eight long-running operation method
so we do have to use blocks to be able to use grand central dispatch go-between
in these two cause i'm learning a little bit about them you'd be amazed at the
amount of stuff that you can do creating your own multithreaded applications
post hole for while about how easy this is not showing you a couple of the
keywords but to prove it it is easy in the next module were actually going to
go through and show how to take an application
from single threaded into multi threaded
using grand central dispatch