Stop threads before killing the worker

It is pretty good idea to kill the threads before killing the worker
because threads are still trying to read from pipe that could be prematurely
closed when workers get killed.