miaoshuai / netlib Goto Github PK
View Code? Open in Web Editor NEW一个自己封装的基于reactor的c++网络库
一个自己封装的基于reactor的c++网络库
在博客中看到作者的开源库连接和介绍,其中ThreadPool的构造函数对于成员threads_默认构造为:
ThreadPool::ThreadPool(int threadNumber)
:threadNumber_(threadNumber),
running_(true),
threads_(threadNumber_)
而在start函数中通过vector的push_back()进行添加:
threads_.push_back(std::make_sharedstd::thread(std::bind(&ThreadPool::threadWork, this)));
这样就会导致threads_实际上有预期的2倍大小,且前半为NULL,进一步,在对象析构或者停止时:
for (auto t : threads_)
{
t->join(); //循环等待线程终止
}
就会导致对空数据操作而引发异常。
建议构造函数更换为:
ThreadPool::ThreadPool(int threadNumber)
:threadNumber_(threadNumber),
running_(true),
threads_(NULL)
以上是我在test中发现的问题,仅供参考。
1 usleep(500); 这个时间是如何评估的?
发现注释掉这个后,append 1W线程,也会直接结束(stop也不管用)。
2 有一些停止不了,阻塞死主线程的情况。
例如,初始化的pool的大小 大于 append的任务数,就会阻塞死在 等待锁/等有任务?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.