Skip to content

Commit a21697b

Browse files
committed
MVar: documentation.
1 parent ba3a121 commit a21697b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The design goals of this gem are:
3434
loosely based on the [MailboxProcessor](http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx)
3535
agent in [F#](http://msdn.microsoft.com/en-us/library/ee370357.aspx)
3636
* [Dataflow](https://github.com/jdantonio/concurrent-ruby/blob/master/md/dataflow.md) loosely based on the syntax of Akka and Habanero Java
37+
* [MVar](https://github.com/jdantonio/concurrent-ruby/blob/master/md/mvar.md) inspired by Haskell
3738

3839
### Semantic Versioning
3940

md/mvar.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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

Comments
 (0)