|
| 1 | +# MVar |
| 2 | + |
| 3 | +An `MVar` is a synchronized single element container. They are empty or contain |
| 4 | +one item. Taking a value from an empty `MVar` blocks, as does putting a value |
| 5 | +into a full one. You can either think of them as blocking queue of length one, |
| 6 | +or a special kind of mutable variable. |
| 7 | + |
| 8 | +On top of the fundamental `#put` and `#take` operations, we also provide a |
| 9 | +`#mutate` that is atomic with respect to operations on the same instance. These |
| 10 | +operations all support timeouts. |
| 11 | + |
| 12 | +We also support non-blocking operations `#try_put!` and `#try_take!`, a `#set!` |
| 13 | +that ignores existing values, and a `#modify!` that yields `MVar::EMPTY` if the |
| 14 | +`MVar` is empty and can be used to set `MVar::EMPTY`. You shouldn't use these |
| 15 | +operations in the first instance. |
| 16 | + |
| 17 | +`MVar is related to M-structures in Id, MVar in Haskell and SyncVar in Scala. |
| 18 | +`See |
| 19 | + |
| 20 | +1. P. Barth, R. Nikhil, and Arvind. M-Structures: Extending a parallel, non- |
| 21 | +strict, functional language with state. In Proceedings of the 5th ACM Conference |
| 22 | +on Functional Programming Languages and Computer Architecture (FPCA), 1991. |
| 23 | + |
| 24 | +2. S. Peyton Jones, A. Gordon, and S. Finne. Concurrent Haskell. In Proceedings of the 23rd Symposium on Principles of Programming Languages (PoPL), 1996. |
| 25 | + |
| 26 | +Note that unlike the original Haskell paper, our `#take` is blocking. This is |
| 27 | +how Haskell and Scala do it today. |
0 commit comments