condition is an undesirable situation that occurs when a device or system attempts to perform two or more operations at the same time, but because of the nature of the device or system, the operations must be done in the proper sequence to be done correctly.” http://searchstorage.techtarget.com/definition/race-condition
Counter do 2 def start(count) do 3 spawn(__MODULE__, :loop, [count]) 4 end 5 6 def next(counter) do 7 send(counter, {:next}) 8 end 9 10 def loop(count) do 11 receive do 12 {:next} -> 13 IO.puts("Current count is: #{count}") 14 loop(count + 1) 15 end 16 end 17 end
#PID<0.63.0> iex(4)> Counter.next(counter) Current count is: 42 {:next} iex(5)> Counter.next(counter) Current count is: 43 {:next} iex(6)> Counter.next(counter) Current count is: 44 {:next}