3 ms·
You're right. For your example thats actually an error, and it wont happen if you `takeMVar` before you start working on the new value. I'm describing a slight
by spion 11y ago
You're right. For your example thats actually an error, and it wont happen if you `takeMVar` before you start working on the new value.
I'm describing a slightly different example there, where its okay to get the old data while updates are being "prepared" (e.g. every item in the dictionary is being fetched from the DB, typical for a server app). In that case, Haskell will work correctly. In Go on the other hand, reusing the data structure may result in a program crash, as Go's built in maps (which might contain that data) are not thread-safe.
(You can't even make the simplest type-safe, thread-safe mutable map that uses a RWMutex automatically under the hood. Because there are no generics)