Answer the question
In order to leave comments, you need to log in
What is what in multithreading?
I'm trying to figure out multithreading for myself. But the more I study, the more I get lost in concepts.
Hence the following questions, just definitions are needed:
What is flow?
What is a queue?
What is the name of one line in the picture (is it a stream, a queue, or something else)?
Answer the question
In order to leave comments, you need to log in
A thread is a chain of tasks (blocks of code) that are executed by a computer. Threads are needed to use multi-core processors more efficiently: each core can execute a separate thread without interruptions ( time-sharing ). Threads on Apple platforms roughly correspond to the traditional understanding of threads .
Threads have a disadvantage: they consume computational resources to create them. If for each small operation (for example, to make a request to the network and get a response) to create a separate thread, this will be slow and inefficient.
queue (DispatchQueue
) is an abstraction from the GCD (Grand Central Dispatch) framework. It was invented in order to get around the problem with the frequent creation of threads. Inside the queue there are exactly the same tasks (blocks of code), but at the same time creating a queue is a less “expensive” process than creating a thread.
In the end, tasks from the queue are still executed on a specific thread. But several queues can share the same thread among themselves - just so as not to create unnecessary ones. Usually, the OS allocates tasks from queues to threads on its own.
The picture shows two lines. The arrows going from top to bottom show adding asynchronous blocks of code to the bottom queue (asynchronous - because the top queue does not wait for the bottom one to complete the task, but moves on).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question