Functions of IOS synchronized

Source: Internet
Author: User

This is actually a lock. If self is accessed by other threads, it will be blocked. This is generally used to protect a deadlock for a single instance.

@ Synchronized (Self ){

// Something like this

Kgoablevalue = _ your instance;

}


1. When two concurrent threads access the synchronized (Self) synchronization code block of the same object, only one thread can be executed within a time period. The other thread must wait until the current thread finishes executing this code block before executing this code block.

2. When a thread accesses a synchronized (Self) synchronization code block of the object, access by other threads to all other synchronized (Self) synchronization code blocks of the object will be blocked.

3. However, when a thread accesses a synchronized (Self) synchronization code block of an object, the other thread can still access parts of the object except the synchronized (this) synchronization code block.

4. The third example also applies to other synchronous code blocks. That is to say, when a thread accesses a synchronized (this) synchronization code block of an object, it obtains the object lock of this object. As a result, access by other threads to all the synchronized code parts of the object is temporarily blocked.

5. The above rules apply to other Object locks.

Related Article

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.