Implement threadpool worker function.