[Haskell-beginners] Designing complex Haskell programs
daniel.trstenjak at gmail.com
Tue Jan 14 12:23:16 UTC 2014
> Out of interest, is there some reason you don't mention TVar's?
The use case here seemed to be more about having shared data which is
only read most of the time and updated occasionally. So the MVar seems
to be a quite good fit for this.
> I thought they are the (modern) way to "build robust systems"
> with "different threads using forkIO"(?)
I think it really depends how your threads are accessing the shared
data. Sometimes the rollbacks of a STM might hurt you more than
waiting for the lock of a MVar.
You could use a TVar here, but you have to be aware, that your
threads might operate on outdated data - if one thread is currently
updating the data - and this might be an issue for your system.
If I'm getting it correctly, then a MVar can't be read by mutliple
threads at once, even if all threads are only reading from it.
That's an advantage of the TVar.
So thinking again about it, having only occasionally writes from
favorably only one thread and reads from multiple threads, then indeed
the TVar might be a quite good fit for this use case.
More information about the Beginners