marekjm / viuavm

Parallel virtual machine designed to reliably run massively concurrent programs
https://viuavm.org/
GNU General Public License v3.0
71 stars 11 forks source link

Threads #87

Closed marekjm closed 8 years ago

marekjm commented 9 years ago

Viua should support programs spanning multiple threads.

To avoid problems with locking, machine-local threads will share no state (i.e. take the Erlang approach of a process-like threads). Sample code:

; create a frame
frame ^[(param 0 (istore 1 42))]

; spawn a thread starting with function foo
thread 2 foo

; join a thread from handle stored in register 2, and store the value it returned in register 3
; this will cause the execution to wait for the thread to finish if needed
tjoin 3 2

Threads can be spawned only from functions (i.e. the callable that the thread is started from must be a function).

marekjm commented 8 years ago

First, the code should be refactored so that the main execution thread is also a thread. Given current state of things, machine is hopelessly singlethreaded.