Reusable Concurrent Data Types Vincent Gramoli 1 and Rachid Guerraoui 2 1 NICTA and University of Sydney vincent.gramoli@sydney.edu.au 2 EPFL rachid.guerraoui@epfl.ch Abstract. This paper contributes to address the fundamental challenge of build- ing Concurrent Data Types (CDT) that are reusable and scalable at the same time. We do so by proposing the abstraction of Polymorphic Transactions (PT): a new programming abstraction that offers different compatible transactions that can run concurrently in the same application. We outline the commonality of the problem in various object-oriented languages and implement PT and a reusable package in Java. With PT, anno- tating sequential ADTs guarantee novice programmers to obtain an atomic and deadlock-free CDT and let an advanced programmer leverage the application se- mantics to get higher performance. We compare our polymorphic synchronization against transaction-based, lock- based and lock-free synchronizations on SPARC and x86-64 architectures and we integrate our methodology to a travel reservation benchmark. Although our reusable CDTs are sometimes less efficient than non-composable handcrafted CDTs from the JDK, they outperform all reusable Java CDTs. 1 Introduction Abstract data types (ADTs) have shown to be instrumental in making sequential pro- grams reusable [1]. ADTs promote (a) extensibility when an ADT is specialized through, for example, inheritance by overriding or adding new methods, and (b) composability when two ADTs are combined into another ADT whose methods invoke the original ones. Key to this reusability is that there is no need to know the internals of an ADT to reuse it: its interface suffices. With the latest technology development of multi-core architectures many programs are expected to scale with a large number of cores: ADTs need thus to be shared by many threads. Unfortunately, most ADTs that export shared methods, often called Concurrent Data Types (CDTs), are not reusable: the programmer can hardly build upon them. For ex- ample, programmers cannot reuse the popular concurrent data types of C++, Java and C# libraries. CDTs typically export a set of methods, guaranteeing that, even if invoked concurrently, each of these methods always appears as if it was executed in sequence. This property, known as atomicity (or linearizability [2]), lets the programmer reason in terms of sequential accesses. However, atomicity is generally not preserved under extension or composition, hence annihilating reusability. Basically, CDTs are synchronized using either lock-based (i.e., mutual exclusion) or lock-free primitives (e.g., compare-and-swap). On the one hand, CDTs that rely R. Jones (Ed.): ECOOP 2014, LNCS 8586, pp. 182–206, 2014. c Springer-Verlag Berlin Heidelberg 2014