Rewrite thread pool implementation to remove some unnecessary synchronization