Introduction to Multithreading principle and Runloop in iOS

Source: Internet
Author: User

Http://mobile.51cto.com/iphone-403490.htm

Introduction to Multithreading principle and Runloop in iOS

The application of threads in the iphone is not uncontrolled, and the official data shows that the main thread of the iphone OS has a stack size of 1M and the second one starts at 512KB. And the value cannot be changed by the compiler switch or the thread API function. Only the main thread has the ability to directly modify the UI. ......>> Details

Brothers topic: UI design basics for the iOS human-Computer Interaction Guide

1 iOS multithreaded programming know how much

There are two ways to implement multithreading in the world of iOS:

Multithreading is a relatively lightweight way to implement multiple code execution paths within a single application. At the system level, programs are executed side-by, and the system is assigned to the execution time of each program based on the time required for the program and the time it takes for other programs to decide. Within each application, however, there is one or more threads of execution that perform different tasks at the same time or in a way that occurs almost simultaneously.

The first type: GCD

Read the full text

2 GCD Usage Tips

What is GCD

Grand Central Dispatch (GCD) is a solution for multi-core programming developed by Apple. This method was first introduced in the Mac OS X 10.6 Snow Leopard and was subsequently introduced into the iOS4.0. GCD is an efficient and powerful alternative to technologies such as Nsthread, Nsoperationqueue, nsinvocationoperation, and it looks like a closure in other languages (Closure), but Apple calls it blocks.

Application examples

Let's look at a programming scenario. We want to do a download page on the iphone feature, which is very simple, is to place a button on the iphone, click on the button, the display of a rotating circle, indicating that the download is in progress, after the download is complete, the content is loaded into a text control on the interface.

Read the full text

3 GCD Introduction (i): basic Concepts and dispatch Queue

What is GCD?

Grand Central Dispatch or GCD, a low-level API, provides a new way to write concurrent programs. From a basic function, GCD is a bit like nsoperationqueue, and they all allow the program to split the task into multiple single tasks and then commit to the work queue to execute concurrently or serially. GCD is more efficient than the nsopertionqueue, and it is not part of the cocoa framework.

In addition to the parallel execution capabilities of the code, GCD also provides a highly integrated event control system. You can set a handle to respond to file descriptors, Mach ports (Mach port for interprocess communication on OS x), processes, timers, signals, user-generated events. These handles are executed concurrently through GCD.

Read the full text

4 GCD Introduction (II): Multi-core performance

Concept

In order to get the most out of multicore in a single process, we need to use multithreading (we don't have to go to the process, it doesn't matter if it's gcd). At the lower level, the GCD global dispatch queue is simply an abstraction of the work thread pool. Once the blocks in these queues are available, they are dispatch to the worker thread. Blocks that are submitted to the user queue will eventually enter the same worker pool through the global queue (unless your user queue is targeting the main thread, but we will never do so to improve the speed of the operation).

There are two ways to "squeeze" the performance of a multi-core system through GCD: the operation of a single task or a group of related tasks into a global queue, and the operation of multiple unrelated tasks or associated tasks into the user queue;

Read the full text

5 GCD Introduction (c):D Ispatch Sources

What is dispatch Sources

In simple terms, dispatch source is an object that monitors certain types of events. When these events occur, it automatically places a block into the execution routine of a dispatch queue.

That seems a little unclear. What types of events are we discussing?

Read the full text

6 GCD Introduction (iv): End

Dispatch Queue hangs

Dispatch queue can be suspended and resumed. Use dispatch_suspend functions to suspend, use dispatch_resume functions to recover. The behavior of these two functions is as you wish. In addition, these two functions can also be used to dispatch source.

One of the areas to note is that the dispatch queue is suspended in block granularity. In other words, suspending a queue does not suspend the currently executing block. It will allow the currently executing block to execute, and then the subsequent block will no longer be executed until the queue is restored.

Read the full text

7 GCD Combat One: Use a serial queue for simple preloading

This article shows you how to use a serial queue to achieve a simple preload, the idea is to use GCD to create a serial queue, and then perform two tasks in this queue: 1. Preload a Viewcontroller 2. Push this viewcontroller in. The article finally provides the source code download, hoped to be helpful to you.

The main idea is to create a serial queue using GCD, and then perform two tasks in this queue: 1. Preload a Viewcontroller 2. Push this viewcontroller into

The code is as follows:

Read the full text

8 GCD Combat II: Resource Competition

Overview

I'll take four steps to get everyone to study the concurrency of the research program. The first step is a basic serial program, and then use GCD to compute it in parallel. If you want to follow the steps to try these programs, you can download the source code. Note, don't run IMAGEGCD2.M, this is a negative.

Source Download: http://down.51cto.com/data/872222

Read the full text

9 iOS Multi-line Cheng experience

iOS multi-threaded First experience is the content of this article, the iphone thread application is not uncontrolled, the official data show that the main thread under the iphone OS stack size is 1M, the second thread it starts with 512KB. And the value cannot be changed by the compiler switch or the thread API function. Only the main thread has the ability to modify the UI directly.

First, nsoperation and Nsoperationqueue

1, an Operation class inherited from Nsoperation, the implementation of the class must have-(void) The Main method.

2, the simplest way to use nsoperation is to put it into the nsoperationqueue.

Read the full text

iphone multi-threaded programming first experience

Look for a long time the IPhone under the multi-threaded programming content, the use of the class is uikit in the Nsthread.

In the Google process, found a lot of text is pleasantly surprised to the title of similar < multi-threaded OS4 to come, and these want to guide the 0S4, the highlight of the task is a multi-tasking, a task for a process, also called multi-process, and multithreading in the early Iphoneos are there.

The concept of the task in the IPHONE OS is an app that you can only do one thing at a time, that is, you can't play the game simultaneously on QQ. And multitasking is the time to do that.

The process is probably as follows:

Read the full text

11 Anatomy iphone Multithreading

iphone Multithreading is the content of this article, multithreading in a variety of programming languages are difficult, many languages to achieve a very troublesome, objective-c although originated from C, but its multithreaded programming is quite simple, can be comparable to Java. This article is mainly from the thread creation and startup, thread synchronization and lock, thread interaction, thread pool, and so on four aspects of the iphone is a simple explanation of multithreading Programming.

One, thread creation and startup

There are two main ways in which thread creation works:

    1. -(ID) init; Designated initializer
    2. -(ID) Initwithtarget: (ID) Target selector: (SEL) Selector object: (ID) argument;

Of course, there is one more special, that is, using the so-called convenient method, which can generate a thread directly and start it without being responsible for the cleanup of the thread. The interface for this method is:

Read the full text

iphone development multi-threaded use and considerations

iphone Development Multi-threaded use and considerations are the content of this article, the main introduction of the iphone SDK Multi-threading methods and considerations. While most PC applications now support multi-threaded /multitasking development, Apple does not recommend multithreaded programming on the IPhone .

But multithreaded programming is, after all, a development trend, and it is said that the upcoming IPhone OS4 will fully support multi-threaded processing. So mastering Multi-threaded programming, in some cases will be able to tap the IPhone 's greater potential.

Start with an example

Start with a routine, the specific code reference here. There are also routines that can be downloaded.

Read the full text

How to use multi-threaded iPhone SDK and Precautions

IPhone SDK Multi-threaded use and considerations are the content of this article to introduce, not to mention, directly into the topic. While most PC applications now support multi-threaded /multitasking development, Apple does not recommend multithreaded programming on the IPhone . But multithreaded programming is, after all, a growing trend, and it is said that the upcoming IPhone OS4 will be fully

While most PC applications now support multi-threaded /multitasking development, Apple does not recommend multithreaded programming on the IPhone . But multithreaded programming is, after all, a development trend, and it is said that the upcoming IPhone OS4 will fully support multi-threaded processing. So mastering Multi-threaded programming, in some cases will be able to tap the IPhone 's greater potential

Start with an example

Start with a routine, the specific code reference here. There are also routines that can be downloaded. The control model of a multithreaded application can be referenced here, typically using a manager/worker model, where we use the Nsthread in the iphone SDK to implement it.

First create a new View-based application project with the name "Tutorialproject". The interface, as shown, uses the Uilabel to implement two parts of the part (both the thread and test components), the thread part contains a uiprogressview and a UIButton, and the test Part contains a value and a uislider.

Read the full text

Application of SQLite in multi-threaded environment

First of all, I often see people complaining that SQLite does not support multithreading. In iOS development, database access must be moved to child threads in order not to block the main thread. In order to solve this contradiction, it is necessary to explore this.

The most authoritative answer to this question is, of course, the "is SQLite threadsafe" on the SQLite website? This question and answer.

Simply put, starting with version 3.3.1, it's thread-safe. The SQLite version of iOS is not below this version:

3.4.0-iphone OS 2.2.1

Read the full text

15 tutorials on multi-threaded iphone programming

The iphone multi-threaded Programming Tutorial is the article to introduce the content, I believe you have also been exposed to multi-threaded use, then this article can also be used as a reference to learn. Not much to say, we look at the contents of the detailed explanation of multithreaded programming.

Multi-threaded programming in iphone: Creating Threads

multithreading in a variety of programming languages are difficult, many languages to achieve a cumbersome, objective-c although originated from C, but its multithreaded programming is quite simple, can be comparable with Java.

One, thread creation and startup

Introduction to Multithreading principle and Runloop in iOS

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.