Better thread handling, and added some optimisations.

Now all the thread logic is in `sched.c`, and the `block.c` file has not
to be aware of the threading stuff, including end of wait command
signal.

When a wait command and a normal command aware both configured, the wait
command will be launched in a thread at the same time as the normal command
on the first update.