Fixed multithreading: tasks run in several threads, program exits correctly.