Made the thread pool stoppable.

Added stop and wait methods to the thread pool so that the client
and server can be stopped in a clean way.