Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在单线程编程的上下文中是否存在 volatile 有用的情况?我知道它用于确保始终在内存中实际检查变量的值,所以在任何情况下,该值可能会以应用程序/编译器不会注意到的方式发生变化(在 ST 应用程序中)?
不,这是没有必要的。它用于在线程之间同步内存内容,以防万一您只有一个线程没有意义。