Lock-Free Dynamically Resizable Arrays

  • Damian Dechev
  • Peter Pirkelbauer
  • Bjarne Stroustrup
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4305)

Abstract

We present a first lock-free design and implementation of a dynamically resizable array (vector). The most extensively used container in the C++ Standard Template Library (STL) is vector, offering a combination of dynamic memory management and constant-time random access. Our approach is based on a single 32-bit word atomic compare-and-swap (CAS) instruction. It provides a linearizable and highly parallelizable STL-like interface, lock-free memory allocation and management, and fast execution. Our current implementation is designed to be most efficient on multi-core architectures. Experiments on a dual-core Intel processor with shared L2 cache indicate that our lock-free vector outperforms its lock-based STL counterpart and the latest concurrent vector implementation provided by Intel by a large factor. The performance evaluation on a quad dual-core AMD system with non-shared L2 cache demonstrated timing results comparable to the best available lock-based techniques. The presented design implements the most common STL vector’s interfaces, namely random access read and write, tail insertion and deletion, pre-allocation of memory, and query of the container’s size. Using the current implementation, a user has to avoid one particular ABA problem.

Keywords

lock-free STL C++ vector concurrency real-time systems 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Alexandrescu, A., Michael, M.: Lock-free data structures with hazard pointers. C++ User Journal (November 2004)Google Scholar
  2. 2.
    An, P., Jula, A., Rus, S., Saunders, S., Smith, T., Tanase, G., Thomas, N., Amato, N., Rauchwerger, L.: STAPL: A Standard Template Adaptive Parallel C++ Library. In: LCPC 2001, Cumberland Falls, Kentucky, pp. 193–208(August 2001)Google Scholar
  3. 3.
    Barnes, G.: A method for implementing lock-free shared-data structures. In: SPAA 1993: Proceedings of the fifth annual ACM symposium on Parallel algorithms and architectures, pp. 261–270. ACM Press, New York (1993)CrossRefGoogle Scholar
  4. 4.
    Becker, P.: Working Draft, Standard for Programming Language C++, ISO WG21N2009 (April 2006)Google Scholar
  5. 5.
    Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to algorithms. MIT Press, Cambridge (2001)MATHGoogle Scholar
  6. 6.
    Detlefs, D.L., Flood, C.H., Garthwaite, A.T., Martin, P.A., Shavit, N.N., Steele Jr., G.L.: Even better DCAS-based concurrent deques. In: Herlihy, M.P. (ed.) DISC 2000. LNCS, vol. 1914, pp. 59–73. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  7. 7.
    Fraser, K.: Practical lock-freedom. Technical Report UCAM-CL-TR-579, University of Cambridge, Computer Laboratory (February 2004)Google Scholar
  8. 8.
    Garlan, D., Reinholtz, W.K., Schmerl, B., Sherman, N.D., Tseng, T.: Bridging the gap between systems design and space systems software. In: SEW 2005, Washington, DC, USA, pp. 34–46. IEEE Computer Society Press, Los Alamitos (2005)Google Scholar
  9. 9.
    Gidenstam, A., Papatriantafilou, M., Tsigas, P.: Allocating memory in a lock-free manner. In: Brodal, G.S., Leonardi, S. (eds.) ESA 2005. LNCS, vol. 3669, pp. 329–342. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  10. 10.
    Harris, T.L.: A pragmatic implementation of non-blocking linked-lists. In: Welch, J.L. (ed.) DISC 2001. LNCS, vol. 2180, pp. 300–314. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  11. 11.
    Harris, T.L., Fraser, K., Pratt, I.A.: A practical multi-word compare-and-swap operation. In: Malkhi, D. (ed.) DISC 2002. LNCS, vol. 2508. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  12. 12.
    Hendler, D., Shavit, N., Yerushalmi, L.: A scalable lock-free stack algorithm. In: SPAA 2004: Proceedings of the sixteenth annual ACM symposium on Parallelism in algorithms and architectures, pp. 206–215. ACM Press, New York (2004)CrossRefGoogle Scholar
  13. 13.
    Herlihy, M.: A methodology for implementing highly concurrent data objects. ACM Trans. Program. Lang. Syst. 15(5), 745–770 (1993)CrossRefGoogle Scholar
  14. 14.
    Herlihy, M., Luchangco, V., Martin, P., Moir, M.: Nonblocking memory management support for dynamic-sized data structures. ACM Trans. Comput. Syst. 23(2), 146–196 (2005)CrossRefGoogle Scholar
  15. 15.
    Herlihy, M.P., Wing, J.M.: Linearizability: a correctness condition for concurrent objects. ACM Trans. Program. Lang. Syst. 12(3), 463–492 (1990)CrossRefGoogle Scholar
  16. 16.
    Intel. Ia-32 intel architecture software developer’s manual, vol. 3: System programming guide (2004)Google Scholar
  17. 17.
    Intel. Reference for Intel Threading Building Blocks, version 1.0 (April 2006)Google Scholar
  18. 18.
    ISO/IEC 14882 International Standard. Programming languages C++. American National Standards Institute (September 1998)Google Scholar
  19. 19.
    Michael, M.: CAS-Based Lock-Free Algorithm for Shared Deques. In: Kosch, H., Böszörményi, L., Hellwagner, H. (eds.) Euro-Par 2003. LNCS, vol. 2790, pp. 651–660. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  20. 20.
    Michael, M.M.: High performance dynamic lock-free hash tables and list-based sets. In: SPAA 2002: Proceedings of the fourteenth annual ACM symposium on Parallel algorithms and architectures, pp. 73–82. ACM Press, New York (2002)CrossRefGoogle Scholar
  21. 21.
    Michael, M.M.: Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects. IEEE Trans. Parallel Distrib. Syst. 15(6), 491–504 (2004)CrossRefGoogle Scholar
  22. 22.
    Michael, M.M.: Scalable lock-free dynamic memory allocation. In: PLDI 2004: Proceedings of the ACM SIGPLAN 2004 Conf. on Programming language design and implementation, pp. 35–46. ACM Press, New York (2004)CrossRefGoogle Scholar
  23. 23.
    Michael, M.M., Scott, M.L.: Correction of a memory management method for lock-free data structures. Technical Report TR599 (1995)Google Scholar
  24. 24.
    Robison, A.: Intel Corporation. Personal communication (April 2006)Google Scholar
  25. 25.
    Shalev, O., Shavit, N.: Split-ordered lists: lock-free extensible hash tables. In: PODC 2003: Proceedings of the twenty-second annual symposium on Principles of distributed computing, pp. 102–111. ACM Press, New York (2003)CrossRefGoogle Scholar
  26. 26.
    Stroustrup, B.: The C++ Programming Language. Addison-Wesley Longman Publishing Co., Inc., Boston (2000)Google Scholar
  27. 27.
    Sundell, H., Tsigas, P.: Lock-Free and Practical Doubly Linked List-Based Deques Using Single-Word Compare-and-Swap. In: Higashino, T. (ed.) OPODIS 2004. LNCS, vol. 3544, pp. 240–255. Springer, Heidelberg (2005)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Damian Dechev
    • 1
  • Peter Pirkelbauer
    • 1
  • Bjarne Stroustrup
    • 1
  1. 1.Texas A&M UniversityUSA

Personalised recommendations