Hello!
I’ve been reading your book and so far I enjoy it a lot. Good job :)
In the book, you have defined such function:
(defn assign-item-to-child [child]
(let [item (first @shopping-list)]
(dosync
(alter assignments assoc child item)
(alter shopping-list disj item))
item))
I’m curios what will happen if many threads invoke it simultaneous. Could it happen that many threads will have the same value in the item
symbol? If so, we would assign the same item to many kids. Shouldn’t we invoke (first @shopping-list)
in the dosync
block? Or maybe we should first (ensure shopping-list)
and then take the first item from this list?