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

What is the visibility principle of volatile?

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

What is the visibility principle of volatile? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Key point 1: bus sniffer (MESI cache consistency principle)

Key point 2: bus lock and cache lock. In order to solve the concurrency problem, the value of the memory area will be locked (memory lock). The value in the bus will be locked before store, and unlocked after the write is completed (most of these are cached row locks, bus locks depend on the situation).

Key 3:

This is to enable a thread running on one CPU to read shared variable updates from another CPU thread. The CPU must first delete the copy of the data in the corresponding cache based on the messages stored in the invalid queue, so that it can be synchronized to the cache of the CPU when other CPU updates the shared variables. The load barrier (Load Barrier) in the memory barrier is used to solve this problem. According to the memory address of the invalid queue content, Load Barrier marks the corresponding data state in the cache using the cache on other CPU as I, so that subsequent read operations on this CPU must first send a Read message to synchronize updates made by other processors to the relevant shared variables to the processor's cache.

When you modify a variable that adds volatile, the variable value is immediately written back to the main memory, and the variable in the main memory is locked before the store, the MESI cache consistency protocol is triggered when the store passes through the bus, and the variable in other cpu working memory is set to an invalid state through the bus sniffer (involving memory barrier). When the cpu completes the write operation of the variable, the variable is unlocked.

After reading the above, have you mastered the visibility principle of volatile? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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

Internet Technology

Wechat

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

12
Report