【发布时间】:2013-08-02 19:45:16
【问题描述】:
我已将一个用 C++ 和 Boost 编写的长期稳定库移植到 Blackberry 10。该库在设备之间传输文件。该库编译和链接良好,运行良好。但是,在传输 1、2 或 3 个文件后,我的 Blackberry 10 设备上总是遇到抛出异常。在源代码中将异常捕获为 boost::system::system_error 表明它是异常 16,文本为“mutex: Resource busy”。
这里是发生异常的源代码:
try
{
. . .
// Find DtpFunctionData for the operation ID, use it to invoke handling function
std::map<int, FunctionData>::iterator iter = _vecFunctionData.find (operationId);
if (iter == _vecDtpClientFunctionData.end ())
return EC_GENERAL_FAILURE;
HANDLINGFUNC_1 handlingFunc = (*iter).second._clientHandlingFunc;
POSTOPFUNC_1 postOpFunc = (*iter).second._clientPostOpFunc;
bool callPostOpOnSuccess = (*iter).second._callPostOpOnSuccess;
// Open a socket opposite the remote peer's TcpPortListener
/* Start: ----- EXCEPTION 16: "mutex: Resource busy" ----- */
boost::asio::io_service io_service;
/* End: ----- EXCEPTION 16: "mutex: Resource busy" ----- */
boost::asio::ip::tcp::socket socket (io_service);
. . .
}
catch (boost::system::system_error& err)
{
LOGLINE (("error", "Boost exception (%d / \"%s\") caught in HandleQueueOperation", err.code ().value(), err.what()));
return EC_EXCEPTION_CAUGHT;
}
跟踪日志行是:
18:37:04 ( 149077264) [error] Boost exception (16 / "mutex: Resource busy") caught in HandleQueueOperation
在上面定义了 boost::asio::io_service 对象的 "start" 和 "end" cmets 之间的某个地方抛出了异常。我在 StackOverflow、Google 等网站上搜索了与“互斥锁:资源繁忙”相关的任何内容,但一无所获。我的代码此时没有访问任何应用程序级别的互斥锁,因此我假设所引用的互斥锁是与 Boost 相关的。
谁能告诉我这条消息的基本含义,以及为什么会抛出“资源繁忙”异常? Blackberry 10 上是否存在与异常相关的已知问题?
提前致谢!
【问题讨论】:
-
io_service将在各种平台内部使用互斥锁来完成多项任务。但是我对BB10并不熟悉。您可以附加一个调试器并在调用站点捕获异常吗?io_service构造函数是否抛出异常?查看堆栈跟踪会很有用。 -
到目前为止,我还没有成功进入 Boost 代码本身,但这绝对是目标的方法——敬请期待。
-
这可能是
boost/asio/detail/impl/posix_mutex.ipp,这是我能找到的唯一一个使用字符串"mutex"抛出system_error的地方。假设 BB10 是 posix,如果 mutex 已经初始化,pthread_mutex_init可能会失败。堆栈跟踪将在这里提供帮助。 -
@SamMiller:+1 评论 reposix_mutex.ipp:我搜索了 Boost 源代码,但没有找到这条线索。你让我看到了“盔甲上的裂缝”——谢谢!
标签: c++ exception boost boost-asio blackberry-10