@Volatile

In order to force changes in a variable to be immediately visible to other threads, we can use the annotation @Volatile, a in the following example:

@Volatile
var shutdownRequested = false

This will guarantee visibility of changes for other threads as soon as the value is changed. This means that if thread X modifies the value of shutdownRequested, thread Y will be able to see the change immediately.

Notice that @Volatile is only available in Kotlin/JVM. For other platforms, it's not available since it relies on the JVM to guarantee volatility.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.235.8