Multithreading Knowledge Point (i)

Source: Internet
Author: User

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)

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.