-
Notifications
You must be signed in to change notification settings - Fork 5
Concurrency design study
Since potion is message-passing based it would be pretty easy to support accessing variables and calling functions in other threads just by adding a MOP mixin to check for the tid
in send (aka 'remoting') when threads are enabled.
See e.g. the OMOP by Stefan Marr.
Some languages require compile-time typing for foreign objects to create efficient remoting. (i.e. :shared
)
callcc
/yield
does not work across threads yet.
We want to support fast lightweight coroutines (callcc/yield) in the same thread (esp. for IO), as well as parallel processing via OS threads for CPU-heavy code.
There are essentially 2 opposing philosophies for MTP.
for calls, control flow:
- non-blocking calls and updates (fork/join) with explicit waits,
async
/wait
(fast, but deadlocking) - blocking calls in
recv
and explicitselect
andyield
(Go - safe)
implicit vs explicit event loop:
- Cilk-like pre-emptive scheduling with work-stealing (also sol)
- cooperative event-loop (GIL: perl, python, ruby)
- user-defined event-loop
for data:
- shared-memory (jvm, .net, ...), vs
- message-passing via channels, either by reference (mailbox - fast) or by copying (Go - safe).
And explicit parallelization by something like pfor
, pwhile
, pmap
, pgrep
,
- with waiting per loop iteration (perl6
hyper
- sorted results) or - waiting at the end (perl6
race
- unsorted, but faster).
async could change the type of upvals automatically
primitives (word-size) allow atomic CAS supported updates. no need to lock or proxy.
- objects need to be locked, when being updated (all), or
- referenced via proxies in threads and updated only by async calls of the owner thread (parrot), or
- immmutable data with internally shared, refcounted subparts (Clojure)
- Does
async
needs to create copies of called closures or just copies of locals (TLS
). - Forbid untyped upvals (access to lexical remotes), or proxy them automatically? (
my $a :shared;
vs upval detection)
- overview: http://www.stefan-marr.de/downloads/marr-phd-2013-supporting-concurrency-abstractions-in-high-level-language-virtual-machines.pdf
- "UNDERSTANDING and EXPRESSING SCALABLE CONCURRENCY" http://www.mpi-sws.org/~turon/turon-thesis.pdf
- qthreads (POSIX only): https://code.google.com/p/qthreads/
- checkedthreads: https://github.com/yosefk/checkedthreads
- parrot: http://perl6advent.wordpress.com/2012/12/11/day-11-parrot-threads/
- sol: http://rsms.me/2012/10/14/sol-a-sunny-little-virtual-machine.html