3 ms·
In the past, I was involved with building a Scheme interpreter which was automatically asynchronous, without need for manually handling it with callbacks. Basi
by metafunctor 10y ago
In the past, I was involved with building a Scheme interpreter which was automatically asynchronous, without need for manually handling it with callbacks.
Basically, it was lightweight threads which would yield execution to other threads whenever waiting for I/O, or explicitly yielding. It allowed for a very straightforward linear programming style, no callback hell.
Coupled with a functional programming style, there was rarely a need for mutexes or other synchronization between threads.
When a thread yielded, the current continuation was captured and resumed when the thread was ready to continue. At the bottom of it all was a simple event loop where the Scheme interpreter dispatched I/O and timeouts. Scheme happens to have support for continuations built in to the language, so the implementation was actually quite simple.
- ambrop7 10y agoI've built something similar but a completely new programming language with backtracking as the major feature. The intended use is dynamic OS configuration especially network interface configuration. The interpreter is single-threaded but there is simple concurrency between the "processes", that is a process yields when it has nothing more to immediately do. Old online demo build through Emscripten (it misses many new features such as functions): https://rawgit.com/ambrop72/badvpn-googlecode-export/wiki/emncd.html https://rawgit.com/ambrop72/badvpn-googlecode-export/wiki/em... Docs currently still dying on Google Code archive: https://code.google.com/archive/p/badvpn/wikis/NCD.wiki https://code.google.com/archive/p/badvpn/wikis/NCD.wiki Source: https://github.com/ambrop72/badvpn https://github.com/ambrop72/badvpn
- umanwizard 10y ago> Basically, it was lightweight threads which would yield execution to other threads whenever waiting for I/O, or explicitly yielding. It allowed for a very straightforward linear programming style, no callback hell. How is this different from a normal multithreaded C program on a POSIX kernel? When I call read(), my thread is suspended until the data comes back, and another thread can run.