skip to main content
research-article
Free Access

Revisiting coroutines

Published:20 February 2009Publication History
Skip Abstract Section

Abstract

This article advocates the revival of coroutines as a convenient general control abstraction. After proposing a new classification of coroutines, we introduce the concept of full asymmetric coroutines and provide a precise definition for it through an operational semantics. We then demonstrate that full coroutines have an expressive power equivalent to one-shot continuations and one-shot delimited continuations. We also show that full asymmetric coroutines and one-shot delimited continuations have many similarities, and therefore present comparable benefits. Nevertheless, coroutines are easier implemented and understood, especially in the realm of procedural languages.

References

  1. Adya, A., Howell, J., Theimer, M., Bolosky, W. J., and Doucer, J. R. 2002. Cooperative task management without manual stack management. In Proceedings of the USENIX Annual Technical Conference. USENIX. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Behren, R., Condit, J., and Brewer, E. 2003. Why events are a bad idea (for high-concurrency servers). In Proceedings of the 9th Workshop on Hot Topics in Operating Systems (HotOS IX). Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Birtwistle, G., Dahl, O.-J., Myhrhaug, B., and Nygaard, K. 1980. Simula Begin. Studentlitteratur, Sweden. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Bruggeman, C., Waddell, O., and Dybvig, R. 1996. Representing control in the presence of one-shot continuations. In Proceedings of the ACM SIGPLAN'96 Conference on Programming Language Design and Implementation (PLDI'96). ACM, 99--107. SIGPLAN Not. 31, 5. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Clocksin, W. and Mellish, C. 1981. Programming in Prolog. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Conway, D. 2000. Rfc 31: Subroutines: Co-routines. http://dev.perl.org/perl6/rfc/31.html.Google ScholarGoogle Scholar
  7. Conway, M. 1963. Design of a separable transition-diagram compiler. Commun. ACM 6, 7, 396--408. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Dahl, O.-J., Dijkstra, E. W., and Hoare, C. A. R. 1972. Hierarchical program structures. In Structured Programming, 2nd ed. Academic Press, London. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Danvy, O. and Filinski, A. 1990. Abstracting control. In Proceedings of the ACM Conference on LISP and Functional Programming. ACM, 151--160. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Dybvig, R. and Hieb, R. 1989. Engines from continuations. Comput. Lang. 14, 2, 109--123. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Felleisen, M. 1985. Transliterating Prolog into Scheme. Tech. rep. 182, Indiana University.Google ScholarGoogle Scholar
  12. Felleisen, M. 1988. The theory and practice of first-class prompts. In Proceedings of the 15th ACM Symposium on Principles of Programming Languages (POPL'88). ACM, 180--190. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Felleisen, M. 1990. On the expressive power of programming languages. In Proceedings of the 3rd European Symposium on Programming (ESOP'90), 134--151. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Felleisen, M. and Friedman, D. 1986. Control operators, the SECD-machine, and the λ-calculus. In Formal Description of Programming Concepts-III, M. Wirsing, Ed. North-Holland, 193--217.Google ScholarGoogle Scholar
  15. Griswold, R. and Griswold, M. 1983. The Icon Programming Language. Prentice-Hall, NJ. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Harper, R., Duba, B., Harper, R., and MacQueen, D. 1991. Typing first-class continuations in ML. In Proceedings of the 18th ACM Symposium on Principles of Programming Languages (POPL'91). ACM, 163--173. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Haynes, C. T. 1987. Logic continuations. J. Logic Program. 4, 157--176. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Haynes, C. T. and Friedman, D. 1987a. Abstracting timed preemption with engines. J. Comput. Lang. 12, 2, 109--121. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Haynes, C. T., Friedman, D., and Wand, M. 1986. Obtaining coroutines with continuations. Comput. Lang. 11, 3/4, 143--153. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Haynes, C. T. and Friedman, D. P. 1987b. Embedding continuations in procedural objects. ACM Trans. Progam. Lang. Syst. 9, 4, 582--598. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Hieb, R. and Dybvig, R. 1990. Continuations and concurrency. In Proceedings of the 2nd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming. ACM, 128--136. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Hieb, R., Dybvig, R., and Anderson III, C. W. 1994. Subcontinuations. Lisp Symbolic Comput. 7, 1, 83--110. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Ierusalimschy, R. 2003. Programming in Lua. Lua.org, Rio de Janeiro, Brazil. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Ierusalimschy, R. and de Moura, A. L. 2008. Some proofs about coroutines. Monografias em Ciẽncia da Computação 04/08, PUC-Rio, Rio de Janeiro, Brazil.Google ScholarGoogle Scholar
  25. Ierusalimschy, R., Figueiredo, L., and Celes, W. 1996. Lua—An extensible extension language. Softw. Pract. & Exper. 26, 6, 635--652. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Johnson, G. and Duggan, D. 1988. Stores and partial continuations as first-class objects in a language and its environment. In Proceedings of the 15th ACM Symposium on Principles of Programming Languages (POPL'88). ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Kelsey, R., Clinger, W., and J. Rees, e. 1998. Revised5 report on the algorithmic language Scheme. Higher-Order Symbolic Comput. 11, 1, 7--105. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Knuth, D. E. 1968. The Art of Computer Programming, Volume 1, Fundamental Algorithms. Addison-Wesley, Reading, MA.Google ScholarGoogle Scholar
  29. Kumar, S., Bruggeman, C., and Dybvig, R. 1998. Threads yield continuations. Lisp Symbolic Comput. 10, 3, 223--236. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Liskov, B., Snyder, A., Atkinson, R., and Schaffert, C. 1977. Abstraction mechanisms in CLU. Commun. ACM 20, 8 (Aug.), 564--576. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Marlin, C. D. 1980. Coroutines: A Programming Methodology, a Language Design and an Implementation. Lecture Notes in Computer Science, vol. 95, Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Moody, K. and Richards, M. 1980. A coroutine mechanism for BCPL. Softw. Pract. & Exper. 10, 10, 765--771.Google ScholarGoogle ScholarCross RefCross Ref
  33. Moura, A., Rodriguez, N., and Ierusalimschy, R. 2004. Coroutines in Lua. J. Universal Comput. Sci. 10, 7, 910--925.Google ScholarGoogle Scholar
  34. Murer, S., Omohundro, S., Stoutamire, D., and Szyperski, C. 1996. Iteration abstraction in Sather. ACM Trans. Progam. Lang. Syst. 18, 1, 1--15. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Pauli, W. and Soffa, M. L. 1980. Coroutine behaviour and implementation. Softw, Pract. & Exper. 10, 3, 189--204.Google ScholarGoogle Scholar
  36. Queinnec, C. and Serpette, B. 1991. A dynamic extent control operator for partial continuations. In Proceedings of the 18th ACM Symposium on Principles of Programming Languages (POPL'91). ACM, 174--184. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Richter, J. 1997. Advanced Windows, 3rd ed. Microsoft Press, Redmond, WA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Schemenauer, N., Peters, T., and Hetland, M. 2001. PEP 255: Simple generators. http://www.python.org/peps/pep-0255.html.Google ScholarGoogle Scholar
  39. Serrano, M., Boussinot, F., and Serpette, B. 2004. Scheme fair threads. In Proceedings of the 6th SIGPLAN International Congress on Principles and Practice of Declarative Programming (PPDP), 203--214. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Sitaram, D. 1993. Handling control. In Proceedings of the ACM SIGPLAN'93 Confrence on Programming Language Design and Implementation (PLDI'93). ACM, SIGPLAN Not. 28, 6. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Sitaram, D. 1994. Models of control and their implications for progamming language design. Ph.D. thesis, Rice University. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Springer, G. and Friedman, D. 1989. Scheme and the Art of Programming. MIT Press, Cambridge, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Tismer, C. 2000. Continuations and stackless Python. In Proceedings of the 8th International Python Conference. Arlington, VA. http://www.python.org/workshops/2000-01/proceedings.html.Google ScholarGoogle Scholar
  44. Wand, M. 1980. Continuation-Based multiprocessing. In Proceedings of the Lisp Conference. ACM, 19--28. Reprinted in Higher-Order Symbolic Comput. 12, 3, 285--299, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Wand, M. and Vaillancourt, D. 2004. Relating models of backtracking. In Proceedings of the 9th ACM SIGPLAN International Conference on Functional Programming. ACM, 54--65. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Wirth, N. 1985. Programming in Modula-2, 3rd, corrected ed. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Revisiting coroutines

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM Transactions on Programming Languages and Systems
        ACM Transactions on Programming Languages and Systems  Volume 31, Issue 2
        February 2009
        128 pages
        ISSN:0164-0925
        EISSN:1558-4593
        DOI:10.1145/1462166
        Issue’s Table of Contents

        Copyright © 2009 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 20 February 2009
        • Accepted: 1 April 2008
        • Received: 1 March 2008
        Published in toplas Volume 31, Issue 2

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article
        • Research
        • Refereed

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!