
Continuations and advanced flow control - gnosis
http://www.ibm.com/developerworks/linux/library/l-advflow/index.html
======
ianso
There was a whole raft of discussions in 2006 on Lambda the Ultimate and
elsewhere about using continuations for page flow in webapps, and ultimately
the most persuasive argument (against) was that continuations implied linear
flow whereas web-page flow could be non-linear, what with the back button,
hyperlinks, and all that.

However, I think that continuations are still very cool, and are _especially_
cool when they can be serialized or written to disk/transmitted/etc., because
this essentially lets you "time/space-shift" your thread/process, since it's
just bits.

Right now, "suspending" a process is something that happens when you close
your laptop or pause a VM, but I think that being able to do this at a much
more fine-grained level of detail is what will allow general cloud-based
computation to really take off, because individual threads would be portable
across computing environments.

~~~
waterhouse
Btw, it is possible to suspend Unix processes from the command line by sending
them the SIGSTOP signal.

    
    
      ;playing a song with iTunes
      $ ps ax | grep iTunes
      401   ??  S      5:29.21 /Applications/iTunes.app/Contents/MacOS/iTunes -psn_0_213044
      $ kill -STOP 401
      ;the song stops playing, and iTunes's CPU usage drops to zero
      $ kill -CONT 401
      ;the song resumes exactly where it was
    

I've done this to, say, Firefox, and resumed it sometime later with no ill
effects that I've been able to detect. (Firefox usually has a secondary Flash
plugin process; the interaction between the two when one is suspended is kind
of interesting, but seemingly benign.)

I've found this useful when I've wanted to throttle some application's
CPU/other resource usage (usually on a laptop) but didn't want to completely
quit it. Also it's just kind of awesome.

~~~
ianso
That is awesome! I wonder if the process could be read out via procfs and
continued elsewhere?

~~~
gwern
I dunno about procfs, but one Linux implementation of
<https://en.wikipedia.org/wiki/Application_checkpointing> is
<http://cryopid.berlios.de/> or apparently <http://dmtcp.sourceforge.net/>

------
dustingetz
i gave a lightning talk this week, maybe someone will find it helpful:

"lets make a blocking API not block. wait, what? (a practical introduction to
continuations)"

<https://docs.google.com/present/view?id=dv9r8sv_82cn7dngcq>

------
rcfox
Does logic programming really count as flow control? To me, it's an entirely
different paradigm, where there is no real flow at all; all statements operate
simultaneously.

~~~
sp332
Prolog might be a "logic programming" language, but the flow control is
explicitly based on backtracking. Each possible solution for each statement is
iterated, _one at a time_ , and the results are fed into the next statements.
The program is basically run as a search through the constraints in depth-
first order.
[http://www.doc.gold.ac.uk/~mas02gw/prolog_tutorial/prologpag...](http://www.doc.gold.ac.uk/~mas02gw/prolog_tutorial/prologpages/search.html)

