Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make the test students understand and send the lock?

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to let the test students understand concurrent locks". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

concurrent

One day, a young man named hulk found a gold coin. At the same time, he took a stab, reducing his health by 10 points.

Assuming hp and coin are stored in the same location (for example, kv database, two data in the same key), in the case of concurrency, the processing of requests intersects in time. For example, in the figure above, f1() handles the logic of hp reduction, f2() handles the logic of coin reduction, and finally the write operation of f1() overrides the write operation of f2().

This is just one of the exceptions, but enough to understand why locks are needed.

pessimistic locking

We lock data when we read it and release it when we write it, and any other data reads are blocked during that time. Such locks are called pessimistic locks. With this pessimistic lock, you can ensure that the data read by the-10 hp request will not be written in other requests, which also guarantees the final correctness of the data.

Since there are pessimistic locks, there are also optimistic locks. To reduce complexity, we don't expand them here. Similarly, lock implementations are varied.

"How to let the test students understand concurrent lock" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report