Uniqueness Types Instead STM

230 views Asked by At

A forum post incidates using uniqueness types instead of STM. I don't understand what it is saying. How is uniqueness types suppose to deal with the problem that STM is trying to deal with where multiple threads are updating the same variable for example?

I've looked at wikipedia's articles on uniqueness types and linear types and its still not clear what the forum post meant.

1

There are 1 answers

0
ewernli On BEST ANSWER

Designing systems where data is shared and mutated concurrently by multiple threads is hard.

Approaches to make concurrency easier include:

  • STM -- With STM, data can still be shared and mutated by multiple threads, but concurrent mutations are detected thanks to the use of transactions.
  • Uniqueness types -- With uniqueness types, at most one reference to an object exists. So, by definition, it is impossible to mutate the same data concurrently (you would need two references at least, one per thread).
  • Immutability -- Avoid the problem of concurrent mutations altogether and share only immutable data.
  • Actors -- Actors rely on asynchronous messages, and serialize the messages they receive, thus avoiding concurrent modifications.