1. For loop is not time consuming, I/O operation is time consuming
2. [Nsthread CurrentThread] Gets the number of the current thread, which is the name of the thread, and if # 1 is the primary thread
3. Use Pthread to open a new thread
/*
Parameter 1: Number address of the thread
Parameter 2: Properties of the thread
Parameter 3: Open thread to execute function void* (*) (void *)
Parameter 4: Parameters passed to the function to be executed
*/
pthread_t ID;
Turn on sub-threads, automatically destroy
int result = Pthread_create (&id, NULL, demo, NULL);
If the return value is 0, it represents success, and the other representative's failure
if (result = = 0) {
NSLog (@ "Turn on thread Success");
}else
{
NSLog (@ "Open thread failed");
}
}
Void* (Demo) (void *param)
{
NSLog (@ "%@", [Nsthread CurrentThread]);
return NULL;
}
4. __bridge bridging can put the strings of the C->oc language
NSString *str = (__bridge NSString *) (param);
5. Three ways to turn on sub-threads:
Mode 1
Nsthread *thread = [[Nsthread alloc]initwithtarget:self selector: @selector (demo) Object:nil];
[Thread start];
Mode 2
[Nsthread Detachnewthreadselector: @selector (Demo) totarget:self Withobject:nil];
Mode 3
[Self Performselectorinbackground: @selector (demo) Withobject:nil];
6. Thread Status: New, ready, run, blocked, dead
7. Properties of the thread:
Thread.Name = @ "T1"; name
[Thread setthreadpriority:0]; priority
[Nsthread currentthread].stacksize/1024 occupies memory
8.//Mutex (single read and write operation)
Lock object: 1 must inherit with NSObject
2: Must be global
@synchronized (self.obj) {locked content}
9. Remember to add contentsize when using Uiscrollview
Self.sv.contentSize = img.size;
10. Download images directly using Nsurl
Nsurl *url = [Nsurl urlwithstring:@ "http://b.hiphotos.baidu.com/image/pic/item/ 08f790529822720ea5d058ba7ccb0a46f21fab50.jpg "];
Download image
NSData *data = [NSData Datawithcontentsofurl:url];
NSData->uiimage
UIImage *img = [UIImage imagewithdata:data];
11
1: String with copy
2: Proxy to use weak (prevent circular referencing self->p (with proxy attribute)->delegate-> Self Loop Reference)
3:block with Copy
Multithreading Knowledge Point (i)