Simple usage of iOS multithreaded management-THREAD,NSOPERATION,GCD

Source: Internet
Author: User
Tags notification center

Multithreading

1. The program is an executable file

2. A process is an operational entity for program execution

3. A process is a collection of threads

4. Multithreading is the opening of multiple lines in a program (a process), which facilitates concurrent execution of multiple tasks.

What is a thread ?

1. Code snippets that execute concurrently in the process

2. Threading is a means of improving code efficiency

3.IOS is mainly used to prevent the screen from suspended animation

4. Threading is the primary means of handling asynchronous tasks

===============================

Nsthread

1.+ (void) Detachnewthreadselector: (SEL) selector totarget: (ID) target withobject: (id) argument;

Function: Open and execute a thread

2.-(Instancetype) Initwithtarget: (ID) Target selector: (SEL) Selector object: (ID) argument

Action: Creates a thread but does not execute, requires a manual call

3.NSThreadWillExitNotification

Function: Listens for this message through the Notification center to achieve the end of the listener thread

4.NSlock

Function: Thread lock

5. How to cancel Nsthread

Http://images.cnblogs.com/cnblogs_com/kenshincui/613474/o_14.jpg

===============================

Nsoperation

1. Nsoperation itself is not a thread, it is a thread operation

2. Its common subclass

1) nsinvocationoperation Specifies the task that the thread will perform by means of the method

2) nsblockoperation Specify the task to perform by block

3) You can inherit the nsoperation and then override the main function to achieve the effect of the custom task

3.NSOperationQueue thread pool, managing threads

You can set the maximum number of threads to open Maxconcurrentoperationcount

If set to 1, it becomes a serial queue, otherwise, the concurrent queue

===============================

GCD

1. What is GCD

GCD is the technology that comes with block after Apple iOS4.0, is the lower level (c) more efficient multithreading technology in Apple Package, GCD (Grand-central-dispatch) is the most common multithreading technology currently used, because it is efficient, concise and practical

Queue type of 2.GCD

1). Main thread Queue Dispatch_get_main_queue ()

2). Child thread Queue dispatch_get_global_queue (0, 0)

3. One-time execution (similar to thread lock) static dispatch_once_t Oncetoken

SIngleton is a custom class that inherits NSObject, what type to write in the timing application

4. Delay execution dispatch_time_t, dispatch_after

5. Custom Queue Dispatch_queue_create

Note: a custom queue opens only one thread, and a serial queue when performing multiple tasks

The results printed below are executed in the thread "number = 2"

6. Grouping and merging Dispatch_group_create

Simple usage of iOS multithreaded management-THREAD,NSOPERATION,GCD

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.