I have to rewrite this code using agents in someway the result of x is 0 (It means that each thread is executed one after one). But I have problems because I do not have enough knowledge about agents use. The original code is:
(def x 0) (let [ t1[t1 (Thread. #(dotimes [_ 10000] (def x (inc x)))) t2 (Thread. #(dotimes [_ 10000] (def x (dec x))))] (.start t1) (.start t2) (.join t1) (.join t2) (println x)) When I want to use an agent with await(agent_name) to make each thread run separately, it does not work, the result is always different from zero. Please any suggestions about this?