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 should have parents #110

Closed marekjm closed 8 years ago

marekjm commented 8 years ago

This will prevent the main/1 orphaned threads, stack corrupted error when a thread spawned by a non-main thread outlives the main/1 function.

Now, if a detached thread spawns another thread, and that spawned thread executes longer that the main/1 thread and is not detached the VM will detect potential stack corruption and abort execution of the program. This is undesirable since it is perfectly OK for a thread to outlive its parent thread if it is detached. However, Viua currently lacks the notion of parent thread so if main/1 exits between the moment a thread is launched and the moment it is detached the VM will abort. An easy fix is to make thread instruction explicitly set a parent on the thread being launched. Then, if main/1 exits and there are undetached threads for which it is the parent thread - VM can be shot down; if there aren't any such threads - the execution can continue.

marekjm commented 8 years ago

Closed, bug this exposed another issue with threading support in Viua's core.