2
"run"
块在EM中是否作为一个整体执行(没有上下文切换)?在这个例子中,if
条款中会出现竞争条件吗?EventMachine中是否存在竞争条件?
EventMachine.run {
@current_value = 0
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => true) do |ws|
ws.onopen {
@current_value += 1
if @current_value >= 4 # Race condition?
# Code Block
@current_value = 0
end
ws.onmessage { |msg|
# puts msg
}
ws.onclose {
# puts "disconnected"
}
}
end
end