Skip to Main content Skip to Navigation

Continuation-Passing C: Program Transformations for Compiling Concurrency in an Imperative Language

Abstract : Most computer programs are concurrent ones: they need to perform several tasks at the same time. Threads and events are two common techniques to implement concurrency. Events are generally more lightweight and efficient than threads, but also more difficult to use. Additionally, they are often not powerful enough; it is then necessary to write hybrid code, that uses both preemptively-scheduled threads and cooperatively-scheduled event handlers, which is even more complex. In this dissertation, we show that concurrent programs written in threaded style can be translated automatically into efficient, equivalent event-driven programs through a series of proven source-to-source transformations. We first propose Continuation-Passing C, an extension of the C programming language for writing concurrent systems that provides very lightweight, unified (cooperative and preemptive) threads. CPC programs are processed by the CPC translator to produce efficient sequentialized event-loop code, using native threads for the preemptive parts. We then define and prove the correctness of these transformations, in particular lambda lifting and CPS conversion, for an imperative language. Finally, we validate the design and implementation of CPC by comparing it to other thread librairies, and by exhibiting our Hekate BitTorrent seeder. We also justify the choice of lambda lifting by implementing eCPC, a variant of CPC using environments, and comparing its performances to CPC.
Document type :
Complete list of metadata
Contributor : Gabriel Kerneis <>
Submitted on : Tuesday, November 13, 2012 - 2:32:49 PM
Last modification on : Saturday, March 28, 2020 - 2:10:14 AM
Long-term archiving on: : Saturday, December 17, 2016 - 10:09:38 AM


  • HAL Id : tel-00751444, version 1



Gabriel Kerneis. Continuation-Passing C: Program Transformations for Compiling Concurrency in an Imperative Language. Programming Languages [cs.PL]. Université Paris-Diderot - Paris VII, 2012. English. ⟨tel-00751444⟩



Record views


Files downloads