We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在从任务队列中取出任务时,用了一个while(task)的写法,会不会过于复杂了。可以稍微简化一下。直接在回调函数里面进行。
void* ThreadPool::threadFunc(void* arg) { pthread_t tid = pthread_self(); ThreadPool* pool = static_cast<ThreadPool*>(arg); while (pool->isRunning_) { pthread_mutex_lock(&pool->mutex_); while (pool->taskQueue_.empty() && pool->isRunning_) { pthread_cond_wait(&pool->condition_, &pool->mutex_); } Task* task = pool->taskQueue_.front(); pool->taskQueue_.pop_front(); pthread_mutex_unlock(&pool->mutex_); task->run(); } return 0; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
在从任务队列中取出任务时,用了一个while(task)的写法,会不会过于复杂了。可以稍微简化一下。直接在回调函数里面进行。
The text was updated successfully, but these errors were encountered: