Skip to content

Concurrency design study

Reini Urban edited this page Nov 2, 2013 · 14 revisions

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. OMOP

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.

Opposing MTP Philosophies

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 explicit select and yield (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

GC + Data

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)

VM

  • 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)

References

Clone this wiki locally