boost mutex C ++ / CLI问题 [英] boost mutex C++/CLI problems

查看:429
本文介绍了boost mutex C ++ / CLI问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Visual Studio 2008 C#64位,我想使用一个库使用boost。所以我在C ++ / CLI中写了一个包装器。我设法定位我得到的错误

I'm developing in Visual Studio 2008 C# for 64bit and I want to use to use a library which uses boost. So I wrote a wrapper in C++/CLI. I managed to target the error I get to

#include <boost/thread/mutex.hpp>.

如果我在C ++ / CLI包装中包含任何文件,它本身包含 < boost / thread / mutex.hpp> 或者如果我直接将它包含在包装中我得到一个System.AccessViolationException尝试读或写受保护的内存。这通常表明其他内存已损坏。

If I include any file in my C++/CLI wrapper that by itself includes <boost/thread/mutex.hpp> or if I include it directly in the wrapper I get a "System.AccessViolationException" "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

我在构建64位的所有内容时非常小心,所以我怀疑问题存在。当我使用相同的库在64位在普通C + +一切正常。我遇到了几个帖子,人们似乎有类似的问题,boost线程,但没有一个解决方案,我发现工作。

I was very carefull in building everything for 64bit so I doubt that the problems is there. When I use the same library in 64 bit in "plain" C++ everything works fine. I came over a couple of posts where people seem to have similar problems with boost threads but none of the solutions I found worked. Does anyone have an idea?

推荐答案

问题是boost.thread使用一些 #pragma section 指令在不使用/ clr构建时是不兼容的,然后静态链接到使用/ clr的代码。

The problem is that boost.thread uses some #pragma section directives that are incompatible when built without /clr then statically linked to code that uses /clr.

我听说重建boost.thread / clr(即,调用bjam时传递 cxxflags =/ clr)修复了问题,但我没有亲自尝试过。

I've heard that rebuilding boost.thread with /clr (i.e., pass cxxflags="/clr" when invoking bjam) fixes the issue, but I haven't tried it personally.

我假设动态链接到boost.thread(而不是静态,这是VC ++的默认值; #define BOOST_THREAD_DYN_LINK 之前包含任何提升标题)

I assume that dynamically linking to boost.thread (rather than statically, which is the default for VC++; #define BOOST_THREAD_DYN_LINK before including any boost headers) should work too, but again, I haven't tried it.

如果这不起作用,请尝试搜索某些 boost 线程 clr tls 你应该在boost邮件列表上发现相当多的帖子,因为这是一个问题。

If that doesn't work, try googling for some combination of boost thread clr tls; you should find quite a few posts on the boost mailing list about it, as this is an old problem.

编辑:已评论这里由Raman Sharma(微软的高级PM),甚至 std :: mutex 不支持与/ clr,所以这并不意外,boost.thread的互斥实现不是。

EDIT: As commented here by Raman Sharma (a senior PM at Microsoft), even std::mutex isn't supported with /clr, so it's no real surprise that boost.thread's mutex implementation isn't either.

这篇关于boost mutex C ++ / CLI问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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