Giter Site home page Giter Site logo

发现一个bug about threadpool HOT 3 OPEN

lzpong avatar lzpong commented on May 14, 2024
发现一个bug

from threadpool.

Comments (3)

sumover avatar sumover commented on May 14, 2024

草, 我就说不光我一个人发现了这个问题....
我想到了一个解决方法就是在线程池中添加一个erase的方法. 从而删除掉该线程.

from threadpool.

sumover avatar sumover commented on May 14, 2024

找到解决方案了, 与其让当前线程直接停止工作, 不如我们让当前线程等待, 因此我们可以使用条件变量来进行. 具体的代码如下:

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.

zephyrize avatar zephyrize commented on May 14, 2024

草, 我就说不光我一个人发现了这个问题.... 我想到了一个解决方法就是在线程池中添加一个erase的方法. 从而删除掉该线程.

这个线程池不仅这一个bug,我刚测试了一下,线程池的动态添加线程功能不是很理想,我把线程池的最大数量设置为5,初始化时线程池的容量设置为4。当我连续添加五个function(每个function睡眠2s),就会发现第五个线程并没有动态增加一个线程来处理任务,而是等其中一个线程处理完才会处理第五个任务。归根结底,在commit的时候,空闲线程数量计数的时机有bug。

此外,线程池偶尔会无法正常退出,不知道哪里出现了问题。

from threadpool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.