Can I do cooperative multi-tasking?

Featuring the Dragonfly web framework

Can I do cooperative multi-tasking?

Postby ralph.ronnquist » Thu Jun 05, 2014 2:10 am

Is there a possibility of a function that lets me pivot the execution, in the way of saving the current environment (i.e., stacks etc) into a pdl of such, then pop and continue with a saved environment?
Thus, I imagine a function, say (pivot store), that firstly makes a blob (copy) of the current exection state, then pushes that onto the given "store" (list of blobs) or, if nil, onto an internal store, then pops a blob from the internal store, before restoring this as execution state, which thus continues. (Of course, the continuation should be as an immediate return from that other call of "pivot", rather than pushing the blob again)
That kind of primitive would open the gate for cooperative multi-tasking, and allow programs with thousands of light-weight "virutally concurrent" pursuits, such as large scale simulations, as well as other domains where "parallel pursuits" design is desired.
I've started with the coding, but I'm not fully on top of the extent of things to include in the execution state blob, and wanted to check here for pointers and thoughts first.
ralph.ronnquist
 
Posts: 178
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Can I do cooperative multi-tasking?

Postby Lutz » Fri Jun 06, 2014 1:55 pm

A Unix thread like API, like you are suggesting, is very expensive to implement in a LISP interpreter managing many stacks beside the processor stack. Unix processes need very little overhead in the interpreter and the OS will also take care of distributing different processes on different cores in modern processors.

newLISP uses Unix forked child processes to implement multiprocessing. You can use either fork and do synchronization yourself using semaphore and wait-pid and pipe for message communications. Or you can use the Cilk based API with spawn, sync and send and receive for agent based messaging implemented with socket pairs.

All this only on OSX, Linux and other Unix. The Cygwin based implementation for fork on Windows has too much problems.

Some code links:

http://www.newlisp.org/newlisp-10.6.0/e ... odcons.lsp
http://www.newlisp.org/newlisp-10.6.0/q ... a-pipefork
http://www.newlisp.org/newlisp-10.6.0/q ... ts/qa-cilk
http://www.newlisp.org/newlisp-10.6.0/q ... qa-message
http://www.newlisp.org/newlisp-10.6.0/q ... /qa-msgbig
Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: Can I do cooperative multi-tasking?

Postby ralph.ronnquist » Sat Jun 07, 2014 1:39 am

Great. Thanks. I suppose mostly it tells me that no sane person should venture into this even if they can make a good argument for having it :-)
Fair enough; and indeed, the newlisp as is, sure is a pleasure to work with anyhow.
ralph.ronnquist
 
Posts: 178
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia


Return to So, what can you actually DO with newLISP?

Who is online

Users browsing this forum: No registered users and 2 guests