progschj / ThreadPool

A simple C++11 Thread Pool implementation
zlib License
7.63k stars 2.21k forks source link

How dose this for loop end? #91

Closed ztf512 closed 2 years ago

ztf512 commented 2 years ago

I just can't understand when this for loop ends: for(;;) // line 41

AbrasiveBoar902 commented 2 years ago

析构的时候stop=true并唤醒所有线程,然后在所有任务完成(tasks.empty())的时候return if(this->stop && this->tasks.empty()) return;

ztf512 commented 2 years ago

析构的时候stop=true并唤醒所有线程,然后在所有任务完成(tasks.empty())的时候return if(this->stop && this->tasks.empty()) return;

懂了,谢谢老哥

XuSShuai commented 1 year ago

I just can't understand when this for loop ends: for(;;) // line 41

I would like to ask, why do I need this line of code?

AbrasiveBoar902 commented 1 year ago

I just can't understand when this for loop ends: for(;;) // line 41

I would like to ask, why do I need this line of code?

为了让worker thread不断循环做取任务、执行的操作,不然worker会在执行一个task之后结束