Abstract
In this paper, we present a small-step operational semantics for a small concurrent language supporting deferred function calls and related constructs in the style of the Go programming language. For lexical scoping, the presence of higher-order functions, but also the presence of the \(\mathrel {\mathtt {defer}}\)-command, requires the notion of closures in the semantics.
Keywords
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
The work was partially supported by the Norwegian-German bilateral PPP project GoRETech (“Go Runtime Enforcement Techniques”).
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
There’s an exception to this guarantee, though. Deferred code is executed independent from whether the goroutine panics or not, but it’s executed only if the enclosing stack frame returns. Divergence may prevent that, and another reason for failing to return is that the goroutine containing the deferred code may be terminated due to the fact that its parent goroutine terminates. See Sect. 2.2.2.
- 2.
In other languages, an alternative semantics for closures exists as well, where, when building the closure, the non-local variables obtain their meaning passing them “by value” instead. Of course, a by-value treatment would make it impossible for deferred code to change the return value, after the main body has been exited, for instance due to a panic. Passing by value can be achieved here by handing over the value explicitly as an extra formal parameter, effectively using a “\(\lambda \)-lifted” version of the deferred code. Indeed, \(\lambda \)-lifting is a transformation used to give semantics to higher-order functions under lexical scoping [27] and an alternative to closures.
- 3.
With the exception that deferred code can be used to change the value of return parameters declared in the function’s signature.
- 4.
Running the example as is, where the main goroutine does not do much else than spawning two child goroutines, it is practically guaranteed that the parent (and with it the child goroutines) terminates before the children start affecting z.
References
Ábrahám, E., de Boer, F.S., de Roever, W.-P., Steffen, M.: A deductive proof system for multithreaded Java with exceptions. Fundam. Informaticae 82(4), 391–463 (2008). (73 pages), An extended version of the 2005 conference contribution to FSEN 2005 and a reworked and shortened version of the University of Kiel, Department of Computer Science Technical report 0303
America, P.: Issues in the design of a parallel object-oriented language. Formal Aspects Comput. 1(4), 366–411 (1989)
Ancona, D., Lagorio, G., Zucca, E.: A core calculus for Java exceptions. SIGPLAN Not. 36, 16–30 (2001)
Anton, K., Thiemann, P.: Typing coroutines. In: Page, R., Horváth, Z., Zsók, V. (eds.) TFP 2010. LNCS, vol. 6546, pp. 16–30. Springer, Heidelberg (2011)
Baker, H., Hewitt, C.: The incremental garbage collection of processes. ACM Sigplan Not. 12, 55–59 (1977)
Belsnes, D., Østvold, B.M.: Mixing threads and coroutines, Unpublished manuscript (2005)
Berdine, J., O’Hearn, P., Reddy, U., Thielecke, H.: Linear continuation-passing. Higher-Order Symbolic Comput. 15(2–3), 181–208 (2002)
Conway, E.M.: Design of a separable transition-diagram compiler. Commun. ACM 6(7), 396–408 (1963)
Dahl, O.-J., Myhrhaug, B., Nygaard, K.: Simula 67, common base language. Technical report S-2, Norsk Regnesentral (Norwegian Computing Center), Oslo, Norway, May 1968
de Boer, F.S.: Reasoning about Dynamically Evolving Process Structures. A Proof Theory for the Parallel Object-Oriented Language POOL. Ph.D. thesis, Free University of Amsterdam (1991)
de Boer, F.S., Clarke, D., Johnsen, E.B.: A complete guide to the future. In: De Nicola, R. (ed.) ESOP 2007. LNCS, vol. 4421, pp. 316–330. Springer, Heidelberg (2007)
de Moura, A.L., Rodriguez, N., Ierusalimschy, R.: Coroutines in Lua. J. Univ. Comput. Sci. 10, 910–925 (2004)
Donovan, A.A.A., Kernighan, B.W.: The Go Programming Language. Addison-Wesley (2015)
Evans Jr., A.: PAL – a language designed for teaching programming linguistics. In: Proceedings of the 1968 23rd ACM National Conference, pp. 395–403. ACM, New York (1968)
Evans Jr., A.: PAL: pedagogic algorithmic language: a reference manual and primer. Unpublished report, Department of Electrical Engineering, MIT (1968)
Felleisen, M., Friedman, D.P.: Control operators, the SECD-machine, and the \(\lambda \)-calculus. In: Wirsing, M. (ed.) Formal Description of Programming Concepts III, pp. 193–217. North-Holland, Amsterdam (1986)
Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: ACM Conference on Programming Language Design and Implementation (PLDI), pp. 237–247. ACM, June 1993. In SIGPLAN Notices 28(6)
The Go programming language specification, August 2015. https://golang.org/ref/spec
Google. The Go programming language (2014). www.golang.org
Gordon, A.D., Hankin, P.D., Lassen, S.B.: Compilation and equivalence of imperative objects. In: Ramesh, S., Sivakumar, G. (eds.) FST TCS 1997. LNCS, vol. 1346, pp. 74–87. Springer, Heidelberg (1997). Full version available as Technical report 429, University of Cambridge Computer Laboratory, June 1997
Halstead Jr., R.H.: Multilisp: a language for concurrent symbolic computation. ACM Trans. Program. Lang. Syst. 7(4), 501–538 (1985)
Hoare, C.A.R.: Communicating sequential processes. Commun. ACM 21(8), 666–677 (1978)
Hoare, C.A.R.: Communicating Sequential Processes. Prentice-Hall, Englewood Cliffs (1985)
Apple Inc.: Swift. A modern programming language that is safe, fast, and interactive, October 2015. https://developer.apple.com/swift/
Jeannin, J.B.: Capsules and closures: a small-step approach. Electron. Notes Theor. Comput. Sci. 276, 191–293 (2011). Proceedings of the Twenty-seventh Conference on the Mathematical Foundations of Programming Semantics (MFPS XXVII)
Jeannin, J.B., Kozen, D.: Computing with capsules. Technical report, Computing and Information Science, Cornell University, January 2011
Johnsson, T.: Lambda lifting: transforming programs to recursive equations. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 190–203. Springer, Heidelberg (1985)
Laird, J.: A calculus of coroutines. In: Díaz, J., Karhumäki, J., Lepistö, A., Sannella, D. (eds.) ICALP 2004. LNCS, vol. 3142, pp. 882–893. Springer, Heidelberg (2004)
Landin, P.J.: The mechanical evaluation of expressions. Comput. J. 6(4), 308–320 (1964)
Liu, H., Qiu, Z.: Go model and object oriented programming. In: Pardo, A., et al. (eds.) SBLP 2015. LNCS, vol. 9325, pp. 59–74. Springer, Heidelberg (2015). doi:10.1007/978-3-319-24012-1_5
Malayeri, D., Aldrich, J.: Integrating nominal and structural subtyping. In: Vitek, J. (ed.) ECOOP 2008. LNCS, vol. 5142, pp. 260–285. Springer, Heidelberg (2008)
Milner, R., Parrow, J., Walker, D.: A calculus of mobile processes, part I/II. Inf. Comput. 100, 1–77 (1992)
Reus, B., Streicher, T.: About hoare logics for higher-order store. In: Caires, L., Italiano, G.F., Monteiro, L., Palamidessi, C., Yung, M. (eds.) ICALP 2005. LNCS, vol. 3580, pp. 1337–1348. Springer, Heidelberg (2005)
Steele, G.L., Sussman, G.J., Scheme: an interpreter for the extended lambda calculus. AI Memo 349, MIT Artificial Intelligence Laboratory (1975)
Steele, G.L., Sussman, G.J.: Scheme: an interpreter for the extended lambda calculus. High.-Order Symbolic Computat. 11, 405–439 (1998)
Summerfield, M.: Programming in Go. Addison-Wesley, Upper Saddle River (2012)
Wang, A., Dahl, O.-J.: Coroutine sequencing in a block structured environment. BIT Numer. Meth. 11(4), 425–449 (1971)
Acknowledgments
I am also grateful for the thorough, insightful, and detailed feedback from the anonymous reviewers which helped improving the paper.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2016 Springer International Publishing Switzerland
About this chapter
Cite this chapter
Steffen, M. (2016). A Small-Step Semantics of a Concurrent Calculus with Goroutines and Deferred Functions. In: Ábrahám, E., Bonsangue, M., Johnsen, E. (eds) Theory and Practice of Formal Methods. Lecture Notes in Computer Science(), vol 9660. Springer, Cham. https://doi.org/10.1007/978-3-319-30734-3_26
Download citation
DOI: https://doi.org/10.1007/978-3-319-30734-3_26
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-30733-6
Online ISBN: 978-3-319-30734-3
eBook Packages: Computer ScienceComputer Science (R0)