Comments (3)
草, 我就说不光我一个人发现了这个问题....
我想到了一个解决方法就是在线程池中添加一个erase的方法. 从而删除掉该线程.
from threadpool.
找到解决方案了, 与其让当前线程直接停止工作, 不如我们让当前线程等待, 因此我们可以使用条件变量来进行. 具体的代码如下:
if (this->auto_release_free_thread && this->_free_thread_counter > this->init_thread_counter) {
std::unique_lock<std::mutex> __thread_lock(this->_threads_lock);
this->_thread_cv.wait(__thread_lock, [this]() -> bool {
return this->_free_thread_counter <= this->init_thread_counter;
});
}
from threadpool.
草, 我就说不光我一个人发现了这个问题.... 我想到了一个解决方法就是在线程池中添加一个erase的方法. 从而删除掉该线程.
这个线程池不仅这一个bug,我刚测试了一下,线程池的动态添加线程功能不是很理想,我把线程池的最大数量设置为5,初始化时线程池的容量设置为4。当我连续添加五个function(每个function睡眠2s),就会发现第五个线程并没有动态增加一个线程来处理任务,而是等其中一个线程处理完才会处理第五个任务。归根结底,在commit的时候,空闲线程数量计数的时机有bug。
此外,线程池偶尔会无法正常退出,不知道哪里出现了问题。
from threadpool.
Related Issues (20)
- addThread 工作线程函数97行99行
- 请问怎么循环实现,执行线程池中的几个线程 HOT 1
- AUTO_GROW的线程大多时候创建完就退出了 HOT 1
- threadpool初始化就抛出异常了 HOT 1
- 在只剩下一个空闲线程时,多个任务同时commit, 会发生什么? HOT 2
- 子线程返回方式矛盾 HOT 1
- 发现一个BUG
- ‘bind’ was not declared in this scope HOT 1
- thread pool 与 numactl 同时使用,出现捕获不到commit的tasks HOT 1
- 自动增长锁,必须有AUTO_GROW宏才会定义,但是在ifndef的判断后使用了它 HOT 3
- 长时间运行后Threadpool为什么会变慢? HOT 1
- 关于 auto task = std::make_shared<std::packaged_task<ResType()>>(std::bind(std::forward<F>(f), std::forward<Args>(args)...) ); HOT 1
- 向 namespace std 添加内容是ub
- 你真的有运行过你的代码吗? HOT 1
- 显示 未定义标识符 "_lockGrow"
- error: no instance of function template "std::threadpool::commit" matches the argument list HOT 1
- idlThrNum是原子变量,是否不需要加锁? HOT 1
- 关于自动释放线程的一个问题
- 单例模式
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from threadpool.