如何将Boost线程池从fifo转换为优先级?

发布于 2024-08-03 15:06:42 字数 750 浏览 2 评论 0原文

我正在研究 Boost 线程池。

我有一个这样的结构:

class SimThreadPool
{
    static SimThreadPool* getInstance();

   boost::threadpool::prio_pool& getThreadPool() { return mThreadPool; }

    simTerrain::SimThreadPool::SimThreadPool()
    : mThreadPool(boost::threadpool::fifo_pool(1))
    {

    }

    boost::threadpool::prio_pool mThreadPool;
}

当我需要一个线程时,我这样调用它:

  SimThreadPool::getInstance()->getThreadPool().schedule(MyThread());

它可以工作。

问题是:如何将该线程池从 fifo 转换为优先级?

我将所有 fifo\_pool 更改为 prio\_pool,但我无法管理它 - 它不起作用。我遇到了一些错误。

在这种情况下如何使用 prio_pool

我想我必须使用 prio_task_func 而不是类,但我想为此目的重新使用现有的算法。

I am working on a Boost thread pool.

I have a structure like this:

class SimThreadPool
{
    static SimThreadPool* getInstance();

   boost::threadpool::prio_pool& getThreadPool() { return mThreadPool; }

    simTerrain::SimThreadPool::SimThreadPool()
    : mThreadPool(boost::threadpool::fifo_pool(1))
    {

    }

    boost::threadpool::prio_pool mThreadPool;
}

When I need a thread, I call it like this:

  SimThreadPool::getInstance()->getThreadPool().schedule(MyThread());

and it works.

The question is: How can I convert this thread pool from fifo to priority?

I changed all my fifo\_pool to prio\_pool, but I could not manage this - it didn't work. I got some errors.

How can I use a prio_pool in this situation?

I think I have to use prio_task_func instead of a class, but I want to re-use my existing algorithms for this purpose.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2024-08-10 15:06:42

我认为您需要将 mThreadPool 声明为:

boost::threadpool::scoped_pool<boost::threadpool::prio_pool, 0> mThreadPool;

在您的类中使用 prio_task_func 之前。

您看过 http://sourceforge.net/projects/threadpool/ 吗?

I think you need to declare mThreadPool as:

boost::threadpool::scoped_pool<boost::threadpool::prio_pool, 0> mThreadPool;

before you use prio_task_func in your class.

Have you looked at http://sourceforge.net/projects/threadpool/ ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文