Asynchronous processing is processing that does not stop another processing during ** execution. ** **
If you use asynchronous processing, while performing a certain processing Because you can execute another process without waiting for the end of that process, ** As a result, it leads to faster processing and realization of responsive GUI. ** **
Swift uses threads to implement asynchronous processing.
A thread is a virtual execution unit that uses a CPU. It is an image of a dedicated institution that performs processing!
Programs usually start in a single thread, the main thread. ** You can also create another thread from it to do the work there. ** **
Processing performed in another thread is executed in parallel with processing in the main thread.
Performing processing using multiple threads in this way is called ** multi-thread processing **.
But if multithreading is not implemented correctly, It can lead to serious problems such as:
**-Memory is exhausted due to excessive thread specifications -Inconsistency occurs when trying to update the same data from multiple threads -A deadlock occurs in which threads wait for each other **
To prevent these problems from occurring Programmers have to keep track of and manage threads.
So it's very convenient, but it's a difficult technique.
There are the following three methods for performing asynchronous processing. ** ・ Method using GCD -Method using Operation and OperationQueue classes ・ Method using Thread class **
Please see the separate article for these methods. ・ [Swift] Asynchronous processing "GCD" -[Swift] Asynchronous processing "Operation class" -[Swift] Asynchronous processing "Thread class"
This is the end of the explanation of asynchronous processing.
Since it is possible to prevent the user from having to wait when performing the thought processing, I think it's a fairly usable function.
Because you have to be careful about how to use it Let's understand and use it well!
Thank you for watching until the end.
Recommended Posts