C ++ primer notes (3)

Source: Internet
Author: User

Srwlock allows us to distinguish the threads (the reader thread) that want to read the value of the resource from the threads (The writer thread) that want to update the value of the resource ).
It is feasible to allow all reader threads to access Shared resources at the same time, because there is no risk of data destruction.
Synchronization is required only when the writer wants to update the resource. In this case, the writer thread should exclusively access the resource:

No other threads, whether reading or writing, are allowed to access resources.


Initialization

Void initializesrwlock (psrwlock srwlock );


The writer thread can call acquiresrwlockexclusive to obtain exclusive access to protected resources.

After the resource is updated, call releasesrwlockexclusive to lock the resource.


The reader thread has two operations:
Void acquiresrwlockshared (psrwlock srwlock );
Void releasesrwlockshared (psrwlock srwlock );
Unsupported: srwlock cannot be obtained recursively. A thread cannot lock the resource multiple times to write the resource multiple times and then release it multiple times.

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.