Linux IPC Sync (ii): Read/write lock

Source: Internet
Author: User

The allocation rules for read and write locks are as follows:

1. As long as no thread holds a specified read-write lock for writing, then any number of threads can hold the read-write lock for reading;

2. A read-write lock can be allocated for write only if no thread holds a specified read-write lock for reading or for writing.

This type of access is also known as shared-exclusive lockout (shared-exclusion)

So I think of a scenario like this:

Thread A to write data, the lock has not been blocked, the period of constant readers to read, thread a starved ... (Verified by the experiment)

int   Pthread_rwlock_init (pthread_rwlock_t *, pthread_rwlockattr_t *); int   Pthread_rwlock_rdlock (pthread_rwlock_t *); int   Pthread_rwlock_tryrdlock (pthread_rwlock_t *); int   Pthread_rwlock_wrlock (pthread_rwlock_t *); int   Pthread_rwlock_trywrlock (pthread_rwlock_t *); int   Pthread_rwlock_unlock (pthread_rwlock_t *); int   Pthread_rwlock_destroy (pthread_rwlock_t *);

Same:

Read-write locks can also be used between processes , by setting the property to Pthread_process_shared

#include <pthread.h>int  pthread_rwlockattr_getpshared (constint *valptr) ; int  int value)

Linux IPC Sync (ii): Read/write lock

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.