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 ;}