ABSTRACT
In Concurrent ML, synchronization abstractions can be defined and passed as values, much like functions in ML. This mechanism admits a powerful, modular style of concurrent programming, called higher-order concurrent programming. Unfortunately, it is not clear whether this style of programming is possible in languages such as Concurrent Haskell, that support only first-order message passing. Indeed, the implementation of synchronization abstractions in Concurrent ML relies on fairly low-level, language-specific details. In this paper we show, constructively, that synchronization abstractions can be supported in a language that supports only first-order message passing. Specifically, we implement a library that makes Concurrent ML-style programming possible in Concurrent Haskell. We begin with a core, formal implementation of synchronization abstractions in the π-calculus. Then, we extend this implementation to encode all of Concurrent ML's concurrency primitives (and more!) in Concurrent Haskell. Our implementation is surprisingly efficient, even without possible optimizations. In several small, informal experiments, our library seems to outperform OCaml's standard library of Concurrent ML-style primitives. At the heart of our implementation is a new distributed synchronization protocol that we prove correct. Unlike several previous translations of synchronization abstractions in concurrent languages, we remain faithful to the standard semantics for Concurrent ML's concurrency primitives. For example, we retain the symmetry of choose, which can express selective communication. As a corollary, we establish that implementing selective communication on distributed machines is no harder than implementing first-order message passing on such machines.
Supplemental Material
- R. Bagrodia. A distributed algorithm to implement the generalized alternative command of CSP. In ICDCS'86: International Conference on Distributed Computing Systems, pages 422--427. IEEE, 1986.Google Scholar
- R. Bornat. A protocol for generalized Occam. Software Practice and Experience, 16 (9): 783--799, 1986. ISSN 0038-0644. Google ScholarDigital Library
- G. N. Buckley and A. Silberschatz. An effective implementation for the generalized input-output construct of CSP. ACM Transactions on Programming Languages and Systems, 5 (2): 223--235, 1983. ISSN 0164-0925. Google ScholarDigital Library
- A. Chaudhuri. A Concurrent ML library in Concurrent Haskell, 2009. Links to proofs and experiments at http://www.cs.umd.edu/avik/projects/cmllch/.Google Scholar
- Avik Chaudhuri and Benjamin Franksen. Hackagedb cml package, 2009. Available at http://hackage.haskell.org/cgi-bin/hackage-scripts/package/cml.Google Scholar
- E. D. Demaine. Protocols for non-deterministic communication over synchronous channels. In IPPS/SPDP'98: Symposium on Parallel and Distributed Processing, pages 24--30. IEEE, 1998. Google ScholarDigital Library
- K. Donnelly and M. Fluet. Transactional events. In ICFP'06: International Conference on Functional Programming, pages 124--135. ACM, 2006. Google ScholarDigital Library
- L. Effinger-Dean, M. Kehrt, and D. Grossman. Transactional events for ML. In ICFP'08: International Conference on Functional Programming, pages 103--114. ACM, 2008. Google ScholarDigital Library
- M. Flatt and R. B. Findler. Kill-safe synchronization abstractions. In PLDI'04: Programming Language Design and Implementation, pages 47--58. ACM, 2004. ISBN 1-58113-807-5. Google ScholarDigital Library
- A. D. Gordon. Functional programming and Input/Output. Cambridge University, 1994. ISBN 0-521-47103-6. Google ScholarDigital Library
- C. A. R. Hoare. Communicating sequential processes. Communications of the ACM, 21 (8): 666--677, 1978. Google ScholarDigital Library
- F. Knabe. A distributed protocol for channel-based communication with choice. In PARLE'92: Parallel Architectures and Languages, Europe, pages 947--948. Springer, 1992. ISBN 3-540-55599-4. Google ScholarDigital Library
- X. Leroy, D. Doligez, J. Garrigue, D. Rémy, and J. Vouillon. The Objective Caml system documentation: Event module, 2008. Available at http://caml.inria.fr/pub/docs/manual-ocaml/libref/Event.html.Google Scholar
- R. Milner, J. Parrow, and D. Walker. A calculus of mobile processes, parts I and II. Information and Computation, 100 (1): 1--77, 1992. Google ScholarDigital Library
- S. L. Peyton-Jones and P. Wadler. Imperative functional programming. In POPL'93: Principles of Programming Languages, pages 71--84. ACM, 1993. Google ScholarDigital Library
- S. L. Peyton-Jones, A. D. Gordon, and S. Finne. Concurrent Haskell. In POPL'96: Principles of Programming Languages, pages 295--308. ACM, 1996. Google ScholarDigital Library
- J. H. Reppy. Concurrent programming in ML. Cambridge University, 1999. ISBN 0-521-48089-2. Google ScholarDigital Library
- J. H. Reppy. Higher-order concurrency. PhD thesis, Cornell University, 1992. Technical Report 92-1852. Google ScholarDigital Library
- J. H. Reppy. First-class synchronous operations. In TPPP'94: Theory and Practice of Parallel Programming. Springer, 1994. Google ScholarDigital Library
- J. H. Reppy and Y. Xiao. Towards a parallel implementation of Concurrent ML. In DAMP'08: Declarative Aspects of Multicore Programming. ACM, 2008.Google Scholar
- G. Russell. Events in Haskell, and how to implement them. In ICFP'01: International Conference on Functional Programming, pages 157--168. ACM, 2001. ISBN 1-58113-415-0. Google ScholarDigital Library
- D. Sangiorgi. From pi-calculus to higher-order pi-calculus, and back. In TAPSOFT'93: Theory and Practice of Software Development, pages 151--166. Springer, 1993. Google ScholarDigital Library
- Wikipedia. Sieve of Eratosthenes, 2009. See http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes.Google Scholar
Index Terms
- A concurrent ML library in concurrent Haskell
Recommendations
A concurrent ML library in concurrent Haskell
ICFP '09In Concurrent ML, synchronization abstractions can be defined and passed as values, much like functions in ML. This mechanism admits a powerful, modular style of concurrent programming, called higher-order concurrent programming. Unfortunately, it is ...
Searching for deadlocks while debugging concurrent haskell programs
ICFP '04: Proceedings of the ninth ACM SIGPLAN international conference on Functional programmingThis paper presents an approach to searching for deadlocks in Concurrent Haskell programs. The search is based on a redefinition of the IO monad which allows the reversal of Concurrent Haskells concurrency primitives. Hence, it is possible to implement ...
Searching for deadlocks while debugging concurrent haskell programs
ICFP '04This paper presents an approach to searching for deadlocks in Concurrent Haskell programs. The search is based on a redefinition of the IO monad which allows the reversal of Concurrent Haskells concurrency primitives. Hence, it is possible to implement ...
Comments