In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the role of linux seqlock and rwlock". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In the case of unequal frequency of reading and writing, it is obviously not a good idea to use a normal mutex.
Because reading data in memory does not cause side effects (except embedded), multiple reads can be performed concurrently without changing the data.
When the read frequency is much greater than the write frequency, if only write and read operations are mutually exclusive and concurrent execution between read and read, it is obvious that the performance of the program can be greatly improved.
So at this time, read-write lock arises at the historic moment. When using a read-write lock, multiple reads can occur concurrently, but as long as a read is in progress, the write must wait.
Its implementation principle is not complicated.
Check whether the write lock has been acquired before acquiring the read lock, and wait if it is acquired. If the write lock is not acquired, add one to the number of readers. When you release the reading lock, you can subtract one from the number of readers.
When acquiring a write lock, the write lock cannot be set to the acquired state until the number of readers is 0.
A similar rwlock has been written before, and on this basis, write and write mutual exclusion and write operation anti-starvation mechanism have been added (in order to support multi-threaded concurrent writing).
From the point of view of the implementation of read-write lock, read-write lock is more preferential to read, as long as there is a read operation, the write operation must wait.
If only one thread writes frequently in a block of memory, other threads only read it occasionally, and write is very preferential, that is, write operations with threads cannot be interrupted.
That's when seqlock comes in handy.
The implementation of seqlock is simpler.
Each seqlock maintains an index index value, which succeeds every time it acquires a write lock from seqlock, and increments the index of the seqlock.
Get the index index value of seqlock before and after each read operation, and re-read the data if the index value is not the same before and after the read operation.
As can be seen from the above mechanism, similar to rwlock, it gives preferential treatment to a frequent operation, but unlike rwlock, seqlock gives preferential treatment to write operations.
This is the end of the content of "what are the functions of linux seqlock and rwlock". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.