IOS30---pthread, nsthread, GCD, nsoperation

Source: Internet
Author: User

Pthread (line libraries, very early technology, understand):
A common set of multithreaded APIs
Suitable for systems such as Unix\linux\windows (Java development also has pthread)
Cross-platform \ Portable
Very difficult to use (all C functions)

C language

Programmers manage the thread life cycle, almost without

Nsthread (Master):
Use more object-oriented
Easy to use, direct manipulation of thread objects

OC language

Programmers manage the thread life cycle (Sugau regardless of death), occasionally using

GCD (powerful, focused):
Designed to replace threading technology such as Nsthread
Make the most of your device's multicore (features)

C language

Automatically manage the thread life cycle, often using


Nsoperation (Key):
Based on gcd (bottom is GCD)
More simple and practical features than GCD.
Use more object-oriented

OC language

Automatically manage the thread life cycle, often using

////VIEWCONTROLLER.M//02-Understanding-pthread Simple Use////Created by Xiaomage on 16/2/18.//2016 little brother. All rights reserved.//#import "ViewController.h"#import<pthread.h>@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; }-(Ibaction) Btnclick: (ID) Sender {//NSLog (@ "%@", [Nsthread CurrentThread]); //1. Create thread object, including header file #import <pthread.h>pthread_t thread; //2. Create a thread function    /*first parameter: Thread object pass address second argument: Thread's property NULL third argument: pointer to function Fourth argument: function needs to accept arguments*/Pthread_create (&thread, NULL, task, NULL); //    //1. Create a Thread objectpthread_t threadb;//    //    //2. Create a thread function//    /*//first parameter: Thread object delivery address//second parameter: Thread's properties NULL//third parameter: pointer to a function//Fourth parameter: parameters to be accepted by the function//     */Pthread_create (&threadb, NULL, task, NULL); Pthread_equal (thread, threadb);}void* Task (void*param) {     for(Nsinteger i =0; i<2; i++) {NSLog (@"%zd----%@", I,[nsthread CurrentThread]); } NSLog (@"%@--------", [Nsthread CurrentThread]); returnNULL;}@end

Ios30---pthread, nsthread, GCD, nsoperation

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.