Thread pool implementation.