Linguistic symbiosis between event loop actors and threads☆
Introduction
Two concurrency models have become predominant in modern programming languages. In mainstream languages such as Java, Smalltalk and C#, concurrency is thread-based: processes are represented as threads which communicate via shared state and which synchronise by means of locking constructs such as monitors [1]. Actor-based concurrency models alternatively represent processes by actors which communicate by means of asynchronous message passing [2]. Both concurrency models have their benefits and drawbacks and either model is appropriate for different tasks [3]. For example, actor-based models are most often used for the construction of reactive, event-driven applications.
Different approaches exist for combining the benefits of both concurrency models. One approach is to construct an event-driven library or framework in a multithreaded language. Well-known examples of this approach are GUI frameworks such as Java AWT or Swing. Another approach is to define a unified concurrency model which incorporates both threads and actors into one language. Our approach, described in this paper, is to define a linguistic symbiosis to enable the integration of the actor-based and thread-based concurrency models of two different programming languages.
A linguistic symbiosis enables programs written in different languages to interoperate [4]. A symbiosis defines a mapping between the language constructs of the different languages. The main difficulty of developing a linguistic symbiosis between an actor-based and a thread-based programming language is to define a mapping which defines a proper synchronisation between both concurrency models. Such synchronisation is required to ensure that the concurrency constraints imposed by an actor-based concurrency model are not violated when its objects can be accessed in the multithreaded language.
There exist many different incarnations of the actor model. In this paper, we focus on actors represented as event loops. We describe how to integrate event loop actors with threads by means of a concrete linguistic symbiosis between AmbientTalk [5], [6], an actor language designed for distributed computing, and Java [7], a multithreaded language with monitor-based synchronisation. The resulting AmbientTalk/Java symbiosis is profitable for both symbionts: AmbientTalk profits from the large amount of available Java software components, while Java profits from AmbientTalk's high-level support for distributed programming.
The contribution of this paper is a mapping between event loop actors and threads which allows them to coexist without violating the properties of the event-driven actor model. This mapping has been reported on earlier [8] but we extend the previously discussed mapping here with more elaborate support for futures. In the following section, we briefly summarise the core problem solved by our contribution. Before delving into any technical details, Section 3 first discusses alternative approaches and related work upon which our contribution relies. Section 4 introduces the AmbientTalk language and its event loop actors in more detail. In Section 5, we provide a general overview of the linguistic symbiosis between AmbientTalk and Java. Subsequently, Section 6 describes the core contribution, showing how threads and event loop actors interact in symbiosis. Section 7 describes a concrete implementation and Section 8 describes concrete applications of the AmbientTalk/Java symbiosis. Before concluding, we discuss the generality of our approach (Section 9) and avenues for future research (Section 10).
Section snippets
Problem statement
We now describe the main concurrency problem that has to be tackled by a symbiosis between event loop actors and threads. As will be explained in more detail in Section 4.3, in the event loop actor model we assume, actors process incoming messages sequentially. This ensures that race conditions on an actor's state cannot occur during message processing. However, if an actor passes part of this state to the thread-based language, this otherwise thread-safe state may become accessible to multiple
Linguistic symbiosis
The reference model that we will use for explaining linguistic symbiosis is that of inter-language reflection [4] which is itself based on an open design of object-oriented languages [9]. The purpose of these models is to clearly identify which objects define the boundaries between two languages (via a data mapping) and to identify consistent rules for crossing the boundaries (via a protocol mapping). Performing a linguistic symbiosis between two languages in order to combine different
AmbientTalk
Before describing the AmbientTalk/Java symbiosis, we briefly introduce the AmbientTalk language, particularly emphasising its concurrency model. AmbientTalk can be regarded as a domain-specific programming language with dedicated language constructs for distributed coordination in mobile ad hoc networks [5], [6]. It enforces an actor-based concurrency model which aligns well with the inherently event-driven nature of distributed systems. In distributed systems, devices may join or leave the
The AmbientTalk/Java symbiosis
Our model for explaining the AmbientTalk/Java linguistic symbiosis is based on that of inter-language reflection [4]. In this model, a linguistic symbiosis consists of:
a data mapping which ensures that data in one language looks like data in the other language, such that the symbiosis becomes as syntactically transparent as possible. For example, it is desirable that Java objects are equally represented as objects in AmbientTalk, such that messages can be sent to objects regardless of their
The actor/thread protocol
In this section, we describe a symbiotic protocol mapping for representing AmbientTalk actors as Java threads, and more interestingly, for streamlining multithreaded concurrency in Java as asynchronous message sending in AmbientTalk.
Implementation
This section describes the detailed implementation of the thread/actor protocol mapping introduced in Section 6.2. The thread/actor mapping occurs in the Java wrapper of an AmbientTalk object. This Java wrapper is implemented by means of Java's standard support for dynamic proxies. When an AmbientTalk object is passed as an argument to a Java method requiring a parameter of an interface type, a dynamic proxy implementing that interface is generated by the symbiosis. The proxy requires an object
Applications
We now give concrete examples of each of the three symbiotic invocations on AmbientTalk objects described in Section 6.2, thereby illustrating how the thread/actor protocol mapping behaves in practice.
Discussion
We discuss the general applicability of our linguistic symbiosis. In particular, we discuss the consequences of Java being the implementation language of AmbientTalk and whether the described protocol mapping is applicable to other event loop actor languages as well.
Research status and future work
The AmbientTalk language is implemented as an interpreter on top of the Java Virtual Machine.6 AmbientTalk is a research artefact, serving as a practical platform for experimentation, but lacking extensive performance optimisations. The interpreter runs on the Java Micro Edition platform and has been successfully deployed on PDAs connected via an ad hoc WiFi network. We are currently planning on applying the symbiosis by
Conclusion
In modern programming languages, concurrency control can be traced back to one of two different schools: actor-based message passing concurrency and thread-based shared-state concurrency. We described a novel approach to safely compose the event loop actors of an actor-based language with the threads of a multithreaded language. More specifically, we described a protocol mapping between AmbientTalk event loop actors and Java threads. The resulting AmbientTalk/Java symbiosis allows AmbientTalk
Acknowledgements
The authors would like to thank Kris Gybels for his suggestions for improvement, in particular the structuring of the section on the actor/thread protocol mapping, and the anonymous referees for their helpful suggestions for improvement.
References (25)
- et al.
Inter-language reflection: a conceptual model and its implementation
Computer Languages Systems & Structures
(2006) Monitors: an operating system structuring concept
Communications of the ACM
(1974)- et al.
Concurrent programming using actors
(1987) - et al.
Actors that unify threads and events
- et al.
Ambient-oriented programming in Ambienttalk
- et al.
Ambienttalk: object-oriented event-driven programming in mobile ad hoc networks
- et al.
The Java language specification
(2000) - et al.
Linguistic symbiosis between actors and threads
- Steyaert P. Open design of object-oriented languages, a foundation for specialisable reflective language frameworks....
- et al.
Symbiotic reflection between an object-oriented and a logic programming language
—a tour of Piccola
Software Architectures and Component Technology
Event-based programming without inversion of control
Cited by (17)
AmbientTalk: Programming responsive mobile peer-to-peer applications with actors
2014, Computer Languages, Systems and StructuresNOW: Orchestrating services in a nomadic network using a dedicated workflow language
2013, Science of Computer ProgrammingUrban life and the ambient in smart cities, learning cities, and future cities
2022, Urban Life and the Ambient in Smart Cities, Learning Cities, and Future CitiesDala: A simple capability-based dynamic language design for data race-freedom
2021, Onward! 2021 - Proceedings of the 2021 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, co-located with SPLASH 2021Algorithmic Governance in Smart Cities: The Conundrum and the Potential of Pervasive Computing Solutions
2018, IEEE Technology and Society Magazine
- ☆
This work is based on an earlier work: Linguistic symbiosis between actors and threads, in: Proceedings of the 2007 International Conference on Dynamic Languages (ESUG/ICDL 2007) ACM, 2007. http://doi.acm.org/10.1145/1352678.1352693.
- 1
Research Assistant of the Fund for Scientific Research Flanders, Belgium (F.W.O.).
- 2
Funded by a doctoral scholarship of the Institute for the Promotion of Innovation through Science and Technology in Flanders (IWT-Vlaanderen), Belgium.