IOS Multithreaded Development

Source: Internet
Author: User

This article is mainly my summary of multithreading, when it is a review for their own, but also to others some reference.

  or from a simple beginning, first introduce some conceptual things, although simple, but the depth of understanding determines whether the use of multi-threaded, but also useful how good.

  Threads: A thread is a single sequential control flow in a program, an entity in a thread, a standard thread consisting of a thread ID, a current instruction pointer (PC), a collection of registers, and a stack .

It has the following properties:

1, light entities. 2, the basic unit of independent Dispatch and dispatch. 3, can be executed concurrently. 4. Share process resources.

The next step is to use the four multithreaded programming options available in iOS:

(a) Pthread

Here is not very detailed to explain it, Baidu said:

The POSIX thread (POSIX threads), referred to as pthreads, is the POSIX standard for threading. The standard defines a complete set of APIs for creating and manipulating threads. In Unix-like operating systems (Unix, Linux, Mac OS x, and so on), pthreads is used as the operating system thread. The Windows operating system also has its ported version of Pthreads-win32.

It is rarely used directly in iOS development. To use it you have to use a series of C interfaces in Pthread.h, using those underlying interfaces to create, schedule, and manage threads, which are relatively complex and have many problems to consider.

Two Nsthread

It is Apple's further encapsulation of pthread and is object-oriented. After encapsulation we face the thread object, and its interface is better understood, more intuitive and convenient to use.

Three Grand Central Dispatch (GCD).

It is a solution to the multi-core programming developed by Apple. Using GCD, it automatically manages the thread's life cycle (creating threads, scheduling tasks, destroying threads), does not require our management at all, we focus on the focus as long as it is in its own task, and puts the task into the appropriate queue. The use of GCD c语言 , combined with Block, makes it more convenient and flexible to use.

(d) nsoperation

Nsoperation is also a basic CGD package after iOS 4.x, it is a CGD object-oriented package, and provides useful and thread-safe establishment status, priority, dependency, and cancellation operations.

IOS Multithreaded Development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.