Abstract
The execution of an application written in a reactive language involves transfer of data and control flow between imperative and reactive abstractions at well-defined points. In a multi-threaded environment, multiple such interactions may execute concurrently, potentially causing data races and event ordering ambiguities. Existing RP languages either disable multi-threading or handle it at the cost of reducing expressiveness or weakening consistency. This paper proposes a model for thread-safe reactive programming (RP) that ensures abort-free strict serializability under concurrency while sacrificing neither expressiveness nor consistency. We also propose an architecture for integrating a corresponding scheduler into the RP language runtime, such that thread-safety is provided "out-of-the-box" to the applications.
We show the feasibility of our proposal by providing and evaluating a ready-to-use implementation integrated into the REScala programming language. The scheduling algorithm is formally proven correct. A thorough empirical evaluation shows that reactive applications build on top of it scale with multiple threads, while the scheduler incurs acceptable performance overhead in a single-threaded configuration. The scalability enabled by our scheduler is roughly on-par with that of hand-crafted application-specific locking and better than the scalability enabled by a scheduler using an off-the-shelf software transactional memory library.
Supplemental Material
- Gul Agha. 1986. Actors: A Model of Concurrent Computation in Distributed Systems. MIT Press, Cambridge, MA, USA. Google Scholar
Digital Library
- Roberto M Amadio, Gérard Boudol, Frédéric Boussinot, and Ilaria Castellani. 2006. Reactive concurrent programming revisited. Electronic Notes in Theoretical Computer Science 162 (2006), 49–60.Google Scholar
Cross Ref
- Engineer Bainomugisha, Andoni Lombide Carreton, Tom van Cutsem, Stijn Mostinckx, and Wolfgang de Meuter. 2013. A survey on reactive programming. ACM Comput. Surv. 45, 4, Article 52 (2013), 34 pages. Google Scholar
Digital Library
- Hal Berenson, Phil Bernstein, Jim Gray, Jim Melton, Elizabeth O’Neil, and Patrick O’Neil. 1995. A Critique of ANSI SQL Isolation Levels. In Proceedings of the 1995 ACM SIGMOD International Conference on Management of Data (SIGMOD ’95). ACM, New York, NY, USA, 1–10. Google Scholar
Digital Library
- Philip A Bernstein, Vassos Hadzilacos, and Nathan Goodman. 1986. Concurrency Control and Recovery in Database Systems. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA. Google Scholar
Digital Library
- Pramod Bhatotia, Pedro Fonseca, Umut A. Acar, Björn B. Brandenburg, and Rodrigo Rodrigues. 2015. iThreads: A Threading Library for Parallel Incremental Computation. In Proceedings of the Twentieth International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS ’15). ACM, New York, NY, USA, 645–659. Google Scholar
Digital Library
- Pramod Bhatotia, Alexander Wieder, Rodrigo Rodrigues, Umut A. Acar, and Rafael Pasquin. 2011. Incoop: MapReduce for Incremental Computations. In Proceedings of the 2Nd ACM Symposium on Cloud Computing (SOCC ’11). ACM, New York, NY, USA, Article 7, 14 pages. Google Scholar
Digital Library
- Nathan G. Bronson, Hassan Chafi, and Kunle Olukotun. 2010. CCSTM: A library-based STM for Scala. In The First Annual Scala Workshop at Scala Days.Google Scholar
- Sebastian Burckhardt, Daan Leijen, Caitlin Sadowski, Jaeheon Yi, and Thomas Ball. 2011. Two for the Price of One: A Model for Parallel and Incremental Computation. In Proceedings of the 2011 ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’11). ACM, New York, NY, USA, 427–444. Google Scholar
Digital Library
- Vinay K. Chaudhri and Vassos Hadzilacos. 1995. Safe Locking Policies for Dynamic Databases. In Proceedings of the Fourteenth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems (PODS ’95). ACM, New York, NY, USA, 233–244. Google Scholar
Digital Library
- Gregory H. Cooper and Shriram Krishnamurthi. 2006. Embedding Dynamic Dataflow in a Call-by-value Language. In Proceedings of the 15th European Conference on Programming Languages and Systems (ESOP’06). Springer-Verlag, Berlin, Heidelberg, 294–308. Google Scholar
Digital Library
- Gianpaolo Cugola and Alessandro Margara. 2012. Processing Flows of Information: From Data Stream to Complex Event Processing. ACM Comput. Surv. 44, 3, Article 15 (June 2012), 62 pages. Google Scholar
Digital Library
- Evan Czaplicki and Stephen Chong. 2013. Asynchronous Functional Reactive Programming for GUIs. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’13). ACM, New York, NY, USA, 411–422. Google Scholar
Digital Library
- Joscha Drechsler, Ragnar Mogk, Guido Salvaneschi, and Mira Mezini. 2018. Thread-Safe Reactive Programming. Technical Report.Google Scholar
- Joscha Drechsler, Guido Salvaneschi, Ragnar Mogk, and Mira Mezini. 2014. Distributed REScala: An Update Algorithm for Distributed Reactive Programming. In Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications (OOPSLA ’14). ACM, New York, NY, USA, 361–376. Google Scholar
Digital Library
- Conal Elliott and Paul Hudak. 1997. Functional Reactive Animation. SIGPLAN Not. 32, 8 (Aug. 1997), 263–273. Google Scholar
Digital Library
- Patrick Th. Eugster, Pascal A. Felber, Rachid Guerraoui, and Anne-Marie Kermarrec. 2003. The many faces of publish/subscribe. ACM Comput. Surv. 35, 2 (June 2003), 114–131. Google Scholar
Digital Library
- Guy Golan-Gueta, Nathan Bronson, Alex Aiken, G. Ramalingam, Mooly Sagiv, and Eran Yahav. 2011. Automatic Fine-grain Locking Using Shape Properties. SIGPLAN Not. 46, 10 (Oct. 2011), 225–242. Google Scholar
Digital Library
- Matthew Hammer, Umut A. Acar, Mohan Rajagopalan, and Anwar Ghuloum. 2007. A Proposal for Parallel Self-adjusting Computation. In Proceedings of the 2007 Workshop on Declarative Aspects of Multicore Programming (DAMP ’07). ACM, New York, NY, USA, 3–9. Google Scholar
Digital Library
- Li Haoyi. 2016. Scala.Rx Web site. https://github.com/lihaoyi/scala.rx (Web).Google Scholar
- Maurice P. Herlihy and Jeannette M. Wing. 1990. Linearizability: A Correctness Condition for Concurrent Objects. ACM Trans. Program. Lang. Syst. 12, 3 (July 1990), 463–492. Google Scholar
Digital Library
- C. A. R. Hoare. 1985. Communicating Sequential Processes. Prentice-Hall, Inc., Upper Saddle River, NJ, USA. Google Scholar
Digital Library
- Alan Jeffrey. 2013. Functional Reactive Programming with Liveness Guarantees. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP ’13). ACM, New York, NY, USA, 233–244. Google Scholar
Digital Library
- Tetsuo Kamina and Tomoyuki Aotani. 2018. Harmonizing Signals and Events with a Lightweight Extension to Java. CoRR abs/1803.10199 (2018). arXiv: 1803.10199 http://arxiv.org/abs/1803.10199Google Scholar
- Neelakantan R. Krishnaswami. 2013. Higher-order Functional Reactive Programming Without Spacetime Leaks. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP ’13). ACM, New York, NY, USA, 221–232. Google Scholar
Digital Library
- Neelakantan R. Krishnaswami, Nick Benton, and Jan Hoffmann. 2012. Higher-order Functional Reactive Programming in Bounded Space. In Proceedings of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’12). ACM, New York, NY, USA, 45–58. Google Scholar
Digital Library
- Vladimir Lanin and Dennis Shasha. 1990. Tree locking on changing trees. Technical Report. New York University, Department of Computer Science, Courant Institute of Mathematical Science. Google Scholar
Digital Library
- Jesse Liberty and Paul Betts. 2011. Programming Reactive Extensions and LINQ (1st ed.). Apress, Berkely, CA, USA. Google Scholar
Digital Library
- Andoni Lombide Carreton, Stijn Mostinckx, Tom Van Cutsem, and Wolfgang De Meuter. 2010. Loosely-Coupled Distributed Reactive Programming in Mobile Ad Hoc Networks. In Objects, Models, Components, Patterns, Jan Vitek (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 41–60. Google Scholar
Digital Library
- Ingo Maier and Martin Odersky. 2012. Deprecating the Observer Pattern with Scala.React. Technical Report.Google Scholar
- Ingo Maier and Martin Odersky. 2013. Higher-Order Reactive Programming with Incremental Lists. In ECOOP 2013 – Object-Oriented Programming, Giuseppe Castagna (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 707–731. Google Scholar
Digital Library
- Alessandro Margara and Guido Salvaneschi. 2014. We Have a DREAM: Distributed Reactive Programming with Consistency Guarantees. In Proceedings of the 8th ACM International Conference on Distributed Event-Based Systems (DEBS ’14). ACM, New York, NY, USA, 142–153. Google Scholar
Digital Library
- A. Margara and G. Salvaneschi. 2018. On the Semantics of Distributed Reactive Programming: The Cost of Consistency. IEEE Transactions on Software Engineering 44, 7 (July 2018), 689–711.Google Scholar
Cross Ref
- Leo A. Meyerovich, Arjun Guha, Jacob Baskin, Gregory H. Cooper, Michael Greenberg, Aleks Bromfield, and Shriram Krishnamurthi. 2009. Flapjax: A Programming Language for Ajax Applications. In Proceedings of the 24th ACM SIGPLAN Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’09). ACM, New York, NY, USA, 1–20. Google Scholar
Digital Library
- Ragnar Mogk, Lars Baumgärtner, Guido Salvaneschi, Bernd Freisleben, and Mira Mezini. 2018. Fault-tolerant Distributed Reactive Programming. In 32nd European Conference on Object-Oriented Programming (ECOOP 2018) (Leibniz International Proceedings in Informatics (LIPIcs)), Todd Millstein (Ed.), Vol. 109. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany, 1:1–1:26.Google Scholar
- Yang Ni, Vijay S. Menon, Ali-Reza Adl-Tabatabai, Antony L. Hosking, Richard L. Hudson, J. Eliot B. Moss, Bratin Saha, and Tatiana Shpeisman. 2007. Open Nesting in Software Transactional Memory. In Proceedings of the 12th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP ’07). ACM, New York, NY, USA, 68–78. Google Scholar
Digital Library
- John Peterson, Valery Trifonov, and Andrei Serjantov. 2000. Parallel Functional Reactive Programming. In Practical Aspects of Declarative Languages, Enrico Pontelli and Vítor Santos Costa (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 16–31. Google Scholar
Digital Library
- José Proença and Carlos Baquero. 2017. Quality-Aware Reactive Programming for the Internet of Things. In Fundamentals of Software Engineering, Mehdi Dastani and Marjan Sirjani (Eds.). Springer International Publishing, Cham, 180–195.Google Scholar
- Aleksandar Prokopec, Philipp Haller, and Martin Odersky. 2014. Containers and Aggregates, Mutators and Isolates for Reactive Programming. In Proceedings of the Fifth Annual Scala Workshop (SCALA ’14). ACM, New York, NY, USA, 51–61. Google Scholar
Digital Library
- Stefan Ramson and Robert Hirschfeld. 2017. Active Expressions: Basic Building Blocks for Reactive Programming. CoRR abs/1703.10859 (2017). arXiv: 1703.10859 http://arxiv.org/abs/1703.10859Google Scholar
- Bob Reynders, Dominique Devriese, and Frank Piessens. 2014. Multi-Tier Functional Reactive Programming for the Web. In Proceedings of the 2014 ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming & Software (Onward! 2014). ACM, New York, NY, USA, 55–68. Google Scholar
Digital Library
- Guido Salvaneschi, Sven Amann, Sebastian Proksch, and Mira Mezini. 2014a. An Empirical Study on Program Comprehension with Reactive Programming. In Proceedings of the 22Nd ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE 2014). ACM, New York, NY, USA, 564–575. Google Scholar
Digital Library
- Guido Salvaneschi, Gerold Hintz, and Mira Mezini. 2014b. REScala: Bridging Between Object-oriented and Functional Style in Reactive Applications. In Proceedings of the 13th International Conference on Modularity (MODULARITY ’14). ACM, New York, NY, USA, 25–36. Google Scholar
Digital Library
- Kensuke Sawada and Takuo Watanabe. 2016. Emfrp: A Functional Reactive Programming Language for Small-scale Embedded Systems. In Companion Proceedings of the 15th International Conference on Modularity (MODULARITY Companion 2016). ACM, New York, NY, USA, 36–44. Google Scholar
Digital Library
- Nir Shavit and Dan Touitou. 1995. Software Transactional Memory. In Proceedings of the Fourteenth Annual ACM Symposium on Principles of Distributed Computing (PODC ’95). ACM, New York, NY, USA, 204–213. Google Scholar
Digital Library
- Sagnak Tasirlar and Vivek Sarkar. 2011. Data-Driven Tasks and Their Implementation. In Proceedings of the 2011 International Conference on Parallel Processing (ICPP ’11). IEEE Computer Society, Washington, DC, USA, 652–661. Google Scholar
Digital Library
- Aaron Turon. 2012. Reagents: Expressing and Composing Fine-grained Concurrency. In Proceedings of the 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’12). ACM, New York, NY, USA, 157–168. Google Scholar
Digital Library
- Pascal Weisenburger, Mirko Köhler, and Guido Salvaneschi. 2018. Distributed System Development with ScalaLoci. Proc. ACM Program. Lang. 2, OOPSLA (Nov. 2018). Google Scholar
Digital Library
Index Terms
Thread-safe reactive programming
Recommendations
Unbounded page-based transactional memory
Proceedings of the 2006 ASPLOS ConferenceExploiting thread level parallelism is paramount in the multicore era. Transactions enable programmers to expose such parallelism by greatly simplifying the multi-threaded programming model. Virtualized transactions (unbounded in space and time) are ...
Time-Based Software Transactional Memory
Software transactional memory (STM) is a concurrency control mechanism that is widely considered to be easier to use by programmers than other mechanisms such as locking. The first generations of STMs have either relied on visible read designs, which ...
Unbounded page-based transactional memory
Proceedings of the 2006 ASPLOS ConferenceExploiting thread level parallelism is paramount in the multicore era. Transactions enable programmers to expose such parallelism by greatly simplifying the multi-threaded programming model. Virtualized transactions (unbounded in space and time) are ...






Comments