Pthread
Statement pthread_t Cthread;
Create a child thread pthread_create (&cthread, NULL, working, NULL);
1.C method, cross-platform creation of sub-threads, support Unix,linux,macos,ios
2. Need to introduce #import <pthread.h>
3. Advantages: can open a thread, the other almost no
4. Cons: Too C, unfriendly
Nsthread (Child threads)
1.NSThread is a lightweight thread object in Cocoa (Macos,ios)
Simple 2.NSThread operation
(1) Create:
Method one, [Nsthread alloc]initwithtarget~ (Start execution)
Method Two, in order to simplify our operation, NSObject encapsulated method, do not have to alloc to create the automatic execution
Nsthread detachnewthreadselector~
(2) Name:
. Name
(3) Nsthread thread with Alloc must call the Start method to execute
[Thread start];
(4) A thread can be canceled, but it needs to be canceled before it executes.
[Thread start];
[Thread Cancel];
Threads run for a certain amount of time, immediately after the cancellation, when the thread is not running, can be canceled,
In the middle of a sentence with a little longer execution time, the thread is running, it's too late to cancel
(5) Loop Create multiple threads, can set priority
The priority is set between (0~1.0), the higher the value, the higher the priority level
There will be times when it doesn't work, nsthread threads are not too good to control
thread.threadpriority = 0.5;
(6) The exit of the thread, the following method, do not go, the code in the main thread execution, the main thread is also one of the threads, so the main thread will also be forced to quit, this method, must be cautious use
[Nsthread exit]
(7) Calling method (sub-thread update UI)
[Self Performselectoronmainthread: @selector (updataui:) withobject:msg Waituntildone:no];
iOS multithreaded--nsthread