升压主题:删除功能的错误使用 [英] Boost Thread: Use of deleted function Error

查看:141
本文介绍了升压主题:删除功能的错误使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个多线程的提升来处理多个请求,并在某个特定消息的接收我将创建一个新的线程来如下处理:

I am trying to use a multi-threading in boost to handle multiple requests and upon the reception of a specific message I will create a new thread to handle it as below:

的main.cpp

/ **
*目标计算机请求处理程序。
*
* @参数味精收到的消息。
* @参数EC错误code。
* /
无效handover_request_handler(odtone :: MIH ::消息和;味精,常量的boost ::系统::错误_ code和; EC)
{
    如果(EC)
    {
        LOG_(0,功能,错误,ec.message());
        返回;
    }
    //做一些东西
}

/** * Destination Machine Request Handler. * * @param msg Received message. * @param ec Error code. */ void handover_request_handler(odtone::mih::message &msg, const boost::system::error_code &ec) { if (ec) { log_(0, FUNCTION, " error: ", ec.message()); return; } // Do some stuff }

无效event_handler(odtone :: MIH ::消息和;味精,常量的boost ::系统::错误_ code和; EC)
{
    如果(EC)
    {
        LOG_(0,功能,错误,ec.message());
        返回;
    }

void event_handler(odtone::mih::message &msg, const boost::system::error_code &ec) { if (ec) { log_(0, FUNCTION, " error: ", ec.message()); return; }

}

当我尝试编译使用B2工具它,我得到以下错误:

When I try to compile it using b2 tool, I get the following errors:

gcc.compile.c ++ ../../bin.v2/app/lte_mih_usr/g​​cc-4.6/debug/link-static/runtime-link-static/main.o
main.cpp中:在功能无效event_handler(odtone :: MIH ::消息和;,常量的boost ::系统::错误_ code&安培;):
main.cpp中:189:69:错误:使用删除功能odtone :: MIH ::消息::消息(常量odtone :: MIH ::消息和;)
从../../inc/odtone/mih/request.hpp:24:0包含在文件中,
                 从的main.cpp:11:

那么如何解决这个问题呢?

So how to solve this problem?

非常感谢。

推荐答案

线程构造函数会将它的参数,而的消息类型是不可拷贝。传递给需要使用的目标函数的引用的boost :: REF(MSG)

The thread constructor copies its arguments, and the message type is not copyable. To pass a reference to the target function you need to use boost::ref(msg)

另外请注意,使用绑定线程是多余的:

Also note that using bind with thread is unnecessary:

boost::thread thrd(&handover_request_handler, boost::ref(msg), boost::ref(ec));

线程构造实现了相同的语义绑定,因此,使用绑定只是增加了不必要的额外拷贝。

The thread constructor implements the same semantics as bind, so using bind just adds unnecessary additional copying.

这篇关于升压主题:删除功能的错误使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆