Junior — Senior
Possible console output results when using volatile
livecode
Task condition
Determine which string options may appear in the console after executing the given code.
class State {
volatile var x = 0
volatile var y = 0
}
fun main() {
val state = State()
val t1 = Thread {
state.x = 1
println(state.y)
}
val t2 = Thread {
state.y = 1
println(state.x)
}
t1.start()
t2.start()
t1.join()
t2.join()
}