IOS multithreading implementation 1-pthread, ios multithreading 1-pthread

Source: Internet
Author: User

IOS multithreading implementation 1-pthread, ios multithreading 1-pthread

A set of universal multi-threaded APIs, written in C language, cross-platform \ portable, suitable for Unix, Linux, Windows and other systems, but it is difficult to use, the life cycle is also managed by programmers. This method is rarely used in iOS programming.

# Import <pthread. h> // click the screen to create a thread (void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {pthread_t thread; // create a thread NSString * str = @ "helloWorld "; // create the parameter // the address of thread Number of parameter 1 // the attribute of thread of parameter 2 // the function to be executed by thread 3 (function pointer) (the third parameter is acceptable, demo, * demo, generally & demo) // parameter of the function to be executed by the 4-thread int result = pthread_create (& thread, NULL, & demo, (_ bridge void *) (str); // _ bridge a conversion from oc type to C type // void * p = (_ bridge void *) (str ); NSLog (@ "over % d", result);} // The void * (demo) (void * param) parameter of the function to be executed by the thread) {NSString * str = (_ bridge NSString *) (param); NSLog (@ "% @", str); return NULL ;}

 

Related Article

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.