ios-Multithreading Day01

Source: Internet
Author: User
Tags mutex

# stack/heap/constant area
-The stack area of the operating memory is fast and the stack storage address is contiguous
-the constant area of operating memory is fast; memory space is only opened once;
-The heap area of the operating memory is slower relative to the stack area and constant area, and the heap area memory space is not contiguous, need addressing
'//stored in the stack ' int num = 10; '
stored in the constant area ' nsstring *str1 = @ "Hello"; '
stored in the heap area ' nsstring *str2 = [NSString stringwithformat:@ "hello_%d", I]; '
``

#创建线程的三种方式
-' Nsthread *thread = [[Nsthread alloc] initwithtarget:self selector: @selector (Demo:) object:@ "Alloc"]; '
-' [Nsthread detachnewthreadselector: @selector (Demo:) totarget:self withobject:@ "Detach"]; '
-' [Self Performselectorinbackground: @selector (Demo:) withobject:@ "perform"]; '

#target和selector的关系
-which method on which object is executed.

# What's @synthesize? What is the use of?
-First, once the setter and getter methods of the property are overridden, the system no longer automatically generates an underlined member variable, and this line of code creates an instance variable name with an underlined prefix, and uses this property to generate getter and setter methods.
-Use ' @synthesize ' for only one purpose-to give an instance variable an individual name, or to add two names to the same variable.
-If you want to block automatic compositing, remember to use ' @dynamic '. The classic usage scenario is where you know that the Getter/setter method has been implemented somewhere, and the compiler doesn't know.
-How to use: ' @synthesize obj2 = _obj2; '

#线程的状态-Life cycle
-Start: Ready state, waiting to be called by the CPU, when called to run state
-sleep/locking: Blocking status
-Exit: Kill completely (abnormal death), * do not call in the main thread *

#线程属性 (Name,stacksize,ismainthread,threadpriority,qualityofservice)
-' name '-thread name
-Set the thread name to log exceptions and the current thread when an exception occurs inside a method that the thread executes
-' stackSize '-stack size
-By default, the stack size is 512K, either the main thread or the child thread
-The stack size can be set ' [Nsthread currentthread].stacksize = 1024 * 1024; '
-Must be a multiple of 4KB
-' ismainthread '-whether the main thread
-' threadpriority '-thread priority
-priority, is a floating-point number that ranges from ' 0~1.0 '
-' 1.0 ' indicates highest priority
-' 0.0 ' indicates the lowest priority
-Default priority is ' 0.5 '
-* * Priority is high only to ensure the likelihood of CPU scheduling is high * *
-' qualityofservice '-quality of service (IOS 8.0 launch)
-Nsqualityofserviceuserinteractive-user interaction, such as drawing or handling user events
-nsqualityofserviceuserinitiated-User needs
-Nsqualityofserviceutility-Utilities, users do not need to get results immediately
-Nsqualityofservicebackground-Backstage
-Nsqualityofservicedefault-default, between user needs and utilities

#NSUInteger和NSInteger的区别

-' Nsinteger ' signed integer (with positive negative number) with '%zd '
-' nsuinteger ' unsigned integer (no negative number) with '%tu '
-is designed to adapt the architecture of 32-bit and 64-bit CPUs.

#线程安全-resource sharing (mutex summary)
-' @ synchronized ' mutex, using thread synchronization technology
-Sync lock/Mutex: can guarantee to be locked code, same time, only one county can operate
-' self ': Lock object, any object that inherits from NSObject can be a lock object, because there is a lock inside, and it is open by default
-Lock object: Must be the global lock object, to ensure that all the threads can access, self is the most convenient to use the lock object
-Mutex lock your range should be as small as possible, but be sure to lock the read and write parts of the resource
-The execution efficiency of the post-yoke program is lower than when it is unlocked, because the thread waits to be unlocked
-Sacrificing performance to ensure security

#原子属性和非原子属性-and Spin lock
-' nonatomic ': Non-atomic properties
-' Atomic ': Atomic properties
-Thread-Safe, property modifier for multithreaded design, is the default value.
-Features: Single write multi-read
-Write multiple reads: Ensure that only one thread can execute the setter method at the same time, but there can be multiple threads executing the Getter method.
-The Atomic property has a lock inside the setter, called a spin lock.
-The setter method of the atomic attribute is thread-safe, but the getter method is not thread-safe.
-Comparison of ' nonatomic ' and ' Atomic ':
-' nonatomic ': Non-thread-safe, suitable for small memory mobile devices.
-' Atomic ': thread-safe, requires a lot of resources. Performance is almost as high as non-atomic properties.

#loadView的注意事项
1. For loading the specified view, once this method is overridden, the storyboard will not load the root view.
2. Call before ' Viewdidload '
3. ' Super.loadview () ' cannot be called
4. Callback with this method when ' Self.view = = Nil '

#ViewController的生命周期

-' Loadview ': Used to load the developed root to try to
-' viewdidload ': Attempt to load complete
-' viewwillappear ': The interface is about to appear on the screen
-' viewdidappear ': The interface has been completely rendered on the screen
-' viewwilldisappear ': The interface is about to disappear from the screen
-' viewdiddisappear ': The interface has completely disappeared
-' Dealloc ': Controller destruction

#什么时候用 ' stong '/' weak '
-The root view and parent view require the use of strong; Child views Use weak
-Object with no strong pointer to use strong; A strong pointer can be weak.

#线程间通信 (How do you do that?) Why can I communicate? )
-Because multiple threads share address space and data space, data from one thread can be supplied directly to other threads, called Inter-thread communication
-' Performselectorinbackground '
-' Performselectoronmainthread '

ios-Multithreading Day01

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.