# Run this in a file.
# Notice how each thread gets its own copy of the environment,
# including the global 'counter' variable.
(var counter 0)
(defn start-thread [name sleep]
(def chan (ev/thread-chan))
(print name " counter is " counter))
(print name " has finished")
(ev/give chan "done"))
# Spawn two threads that increment counter
(def chan-a (start-thread "Slow thread" 0.8))
(def chan-b (start-thread "Fast thread" 0.45))
# Wait for both threads to finish
(print "Global counter is still " counter)