Added part A of threads

Not 100% tested (switching between threads at runtime is still missing).