[召唤老邓]Mingw 对 c++0x 的 thread 支持怎么样了?

fallening 2011-03-08 03:11:11
当前有什么解决方案不?
郁闷中,这几天自己编译了4.6和 4.5,都不能用。


#include <thread>
void f(){}
void g(){}

int main()
{
std::thread t1( f );
std::thread t2( g );
t1.join();
t2.join();
return 0;
}
...全文
636 42 打赏 收藏 转发到动态 举报
写回复
用AI写文章
42 条回复
切换为时间正序
请发表友善的回复…
发表回复
fallening 2011-03-29
  • 打赏
  • 举报
回复
I am very sorry for keeping this thread open for such a long time.

Thank you every body.
fallening 2011-03-15
  • 打赏
  • 举报
回复
[Quote=引用 38 楼 xunxun1982 的回复:]

引用 37 楼 fallening 的回复:

引用 34 楼 xunxun1982 的回复:

在此重新说明下,由于pthread w32的头文件符号导出不同,在shared和static编译时会有区别。
如果你编译成shared版的pthreads,那么直接链接时加入-lpthread即可
如果是static版的,要在编译时必须加入-DPTW32_STATIC_LIB,在链接时加……
[/Quote]

我想问题可能出在这里了

谢谢
我尝试一下再说
iambic 2011-03-15
  • 打赏
  • 举报
回复
估计就算支持也不稳定。不敢用。
xunxun 2011-03-15
  • 打赏
  • 举报
回复
[Quote=引用 37 楼 fallening 的回复:]

引用 34 楼 xunxun1982 的回复:

在此重新说明下,由于pthread w32的头文件符号导出不同,在shared和static编译时会有区别。
如果你编译成shared版的pthreads,那么直接链接时加入-lpthread即可
如果是static版的,要在编译时必须加入-DPTW32_STATIC_LIB,在链接时加入-lpthread

我从 google co……
[/Quote]
你在哪里用到pthread.h时,那个源码就必须使用-DPTW32_STATIC_LIB进行编译,因为pthread static版没有imp_pthread_create之类的符号,只有pthread_create
fallening 2011-03-15
  • 打赏
  • 举报
回复
[Quote=引用 34 楼 xunxun1982 的回复:]

在此重新说明下,由于pthread w32的头文件符号导出不同,在shared和static编译时会有区别。
如果你编译成shared版的pthreads,那么直接链接时加入-lpthread即可
如果是static版的,要在编译时必须加入-DPTW32_STATIC_LIB,在链接时加入-lpthread
[/Quote]
我从 google code 上下载了你打包的 gcc -- 4.5.3 static snapshot
加入 -DPTW32_STATIC_LIB 编译问题依旧
或者你是指编译 thread.cc 那几个文件的时候要 -DPTW32_STATIC_LIB ?
xunxun 2011-03-14
  • 打赏
  • 举报
回复
[Quote=引用 29 楼 fallening 的回复:]

引用 25 楼 redleaves 的回复:

你检查一下你所用的pthread库,它导出的函数不是DLL版本的.而你编译thread.cc时引用的却是DLL版.所以符号找不到了.一般网上发布的pthread库有几个不同的导出库,你把mingw里的libpthread.a换成DLL版本的导出库就可以了.

pthread w32 只有这几个 make 选项
C/C++ code
Ru……
[/Quote]
你是从哪里下载的呢?我一般用他的cvs,编译没有问题。
fallening 2011-03-14
  • 打赏
  • 举报
回复
[Quote=引用 25 楼 redleaves 的回复:]

你检查一下你所用的pthread库,它导出的函数不是DLL版本的.而你编译thread.cc时引用的却是DLL版.所以符号找不到了.一般网上发布的pthread库有几个不同的导出库,你把mingw里的libpthread.a换成DLL版本的导出库就可以了.
[/Quote]
pthread w32 只有这几个 make 选项
Run one of the following command lines:
make clean GC (to build the GNU C dll with C cleanup code)
make clean GCE (to build the GNU C dll with C++ exception handling)
make clean GC-inlined (to build the GNU C inlined dll with C cleanup code)
make clean GCE-inlined (to build the GNU C inlined dll with C++ exception hand
ling)
make clean GC-static (to build the GNU C inlined static lib with C cleanup c
ode)
make clean GC-debug (to build the GNU C debug dll with C cleanup code)
make clean GCE-debug (to build the GNU C debug dll with C++ exception handli
ng)
make clean GC-inlined-debug (to build the GNU C inlined debug dll with C clea
nup code)
make clean GCE-inlined-debug (to build the GNU C inlined debug dll with C++ ex
ception handling)
make clean GC-static-debug (to build the GNU C inlined static debug lib with
C cleanup code)

GCE 编译不通过, GC 的则会出上边的错误

我记得boost 也是出上边的错误的,不过指定了 BOOST_THREAD_USE_LIB 就好了
herman~~ 2011-03-14
  • 打赏
  • 举报
回复
mark 没注意过这个问题
hongwenjun 2011-03-14
  • 打赏
  • 举报
回复
gcc -v 可以看出 编译选项,看到是否支持


Using built-in specs.
Target: i686-mingw32
Configured with: ../../src/gcc-4.4.5/configure --prefix=/mingw --host=i686-mingw
32 --target=i686-mingw32 --build=i686-pc-linux-gnu --enable-languages=c,c++ --en
able-static --enable-cxx-flags='-fno-function-sections -fno-data-sections' --ena
ble-fully-dynamic-string --enable-version-specific-runtime-libs --enable-threads
=win32 --enable-libgomp --enable-libiconv --disable-shared --disable-nls --disab
le-werror --disable-libstdcxx-pch --disable-win32-registry --disable-sjlj-except
ions --with-dwarf2 --with-gmp=/home/loaden/AUR/mingw32/depends --with-mpfr=/home
/loaden/AUR/mingw32/depends --with-pkgversion='QP MinGW32' --with-bugurl=http://
qp-gcc.googlecode.com
Thread model: win32
gcc version 4.4.5 (QP MinGW32)
xunxun 2011-03-14
  • 打赏
  • 举报
回复
在此重新说明下,由于pthread w32的头文件符号导出不同,在shared和static编译时会有区别。
如果你编译成shared版的pthreads,那么直接链接时加入-lpthread即可
如果是static版的,要在编译时必须加入-DPTW32_STATIC_LIB,在链接时加入-lpthread
xunxun 2011-03-14
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 fallening 的回复:]

引用 19 楼 redleaves 的回复:

楼主可以参考我以前发的帖子

http://topic.csdn.net/u/20090721/23/f57c4e3c-5022-493e-8745-d74b123cce9b.html

能帮我看下这个么?
Assembly code

c:\workspace>g++ thread_test.cc -std=c++0x -g -……
[/Quote]
这个好像用的是我的gcc版本,我的是static版的,编译时必须加入-DPTW32_STATIC_LIB
在里面我已经说明了
xunxun 2011-03-14
  • 打赏
  • 举报
回复
[Quote=引用 31 楼 fallening 的回复:]

引用 30 楼 xunxun1982 的回复:

引用 29 楼 fallening 的回复:

引用 25 楼 redleaves 的回复:

你检查一下你所用的pthread库,它导出的函数不是DLL版本的.而你编译thread.cc时引用的却是DLL版.所以符号找不到了.一般网上发布的pthread库有几个不同的导出库,你把mingw里的libpthread.a换成DLL版本的……
[/Quote]
shared版使用

$ make clean GC-inlined
$ cp libpthreadGC2.a /mingw/lib/libpthread.a
$ cp pthread.h sched.h semaphore.h /mingw/include/
$ cp pthread.h pthreadGC2.dll /mingw/bin/

static版使用

$ make clean GC-static
$ cp libpthreadGC2.a /mingw/lib/libpthread.a
$ cp pthread.h sched.h semaphore.h /mingw/include/

具体可以参见我写的mingw gcc4.5.x编译过程

http://code.google.com/p/pcxprj/wiki/GCC45xBuildbyPcX
fallening 2011-03-14
  • 打赏
  • 举报
回复
[Quote=引用 30 楼 xunxun1982 的回复:]

引用 29 楼 fallening 的回复:

引用 25 楼 redleaves 的回复:

你检查一下你所用的pthread库,它导出的函数不是DLL版本的.而你编译thread.cc时引用的却是DLL版.所以符号找不到了.一般网上发布的pthread库有几个不同的导出库,你把mingw里的libpthread.a换成DLL版本的导出库就可以了.

pthread w32 只有这……
[/Quote]
cvs 的这个:

cvs -d :pserver:anoncvs@sourceware.org:/cvs/pthreads-win32 login
{enter ``anoncvs'' for the password}
cvs -d :pserver:anoncvs@sourceware.org:/cvs/pthreads-win32 checkout pthreads


和 ftp 的这个:
ftp://sourceware.org/pub/pthreads-win32/


都尝试过
fallening 2011-03-11
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 redleaves 的回复:]

楼主可以参考我以前发的帖子

http://topic.csdn.net/u/20090721/23/f57c4e3c-5022-493e-8745-d74b123cce9b.html
[/Quote]
能帮我看下这个么?

c:\workspace>g++ thread_test.cc -std=c++0x -g -o tt -lpthread -static
C:\Users\feng\AppData\Local\Temp\ccFpiDZe.o: In function `_gthread_equal':
c:/downloads/mingw_win32_gcc4.5.3static_snapshots/bin/../lib/gcc/i686-pc-mingw32
/4.5.3/include/c++/i686-pc-mingw32/bits/gthr-posix.h:701: undefined reference to
`_imp__pthread_equal'
c:/downloads/mingw_win32_gcc4.5.3static_snapshots/bin/../lib/gcc/i686-pc-mingw32
/4.5.3\libstdc++.a(thread.o):thread.cc:(.text+0x2d): undefined reference to `_im
p__pthread_create'
c:/downloads/mingw_win32_gcc4.5.3static_snapshots/bin/../lib/gcc/i686-pc-mingw32
/4.5.3\libstdc++.a(thread.o):thread.cc:(.text+0x50): undefined reference to `_im
p__pthread_join'
c:/downloads/mingw_win32_gcc4.5.3static_snapshots/bin/../lib/gcc/i686-pc-mingw32
/4.5.3\libstdc++.a(thread.o):thread.cc:(.text+0x6c): undefined reference to `_im
p__pthread_detach'
c:/downloads/mingw_win32_gcc4.5.3static_snapshots/bin/../lib/gcc/i686-pc-mingw32
/4.5.3\libstdc++.a(thread.o):thread.cc:(.text+0x96): undefined reference to `_im
p__pthread_equal'
collect2: ld returned 1 exit status
老邓 2011-03-11
  • 打赏
  • 举报
回复
[Quote=引用 27 楼 xunxun1982 的回复:]
但为啥OpenMP可以呢?这个也是基于pthread
[/Quote]
没用过OpenMP。
不过std::thread显然没有专门针对Windows平台处理。
看到其基于低效的pthread,我已经放弃在实际工程中使用它了。
当初研究三天的原因是:Linux下用的很好,所以想把Windows平台下也搞定,然后集成到我编译的MinGW版本中。
其实在Windows平台,使用系统自带的内存池非常好用的。
简单一封装就可以了。
只是,跨平台性就不好了。

在线程封装上,我觉得Qt要比wxWidgets做的好!
xunxun 2011-03-11
  • 打赏
  • 举报
回复
[Quote=引用 26 楼 loaden 的回复:]

不好意思,这几天很忙,一直没上来。
MinGW为什么不开启std::thread的支持?原因很简单:问题太多。
我非常奇怪MinGW为什么要基于pthread来支持std::thread,而不是基于_beginthread/_endthread,即:boost::thread的实现。

所以,建议你还是放弃吧。
我曾经为了这个std::thread的支持,研究了3天,也没搞定。
[/Quote]
但为啥OpenMP可以呢?这个也是基于pthread
老邓 2011-03-11
  • 打赏
  • 举报
回复
不好意思,这几天很忙,一直没上来。
MinGW为什么不开启std::thread的支持?原因很简单:问题太多。
我非常奇怪MinGW为什么要基于pthread来支持std::thread,而不是基于_beginthread/_endthread,即:boost::thread的实现。

所以,建议你还是放弃吧。
我曾经为了这个std::thread的支持,研究了3天,也没完全搞定:改头文件的方法,会有很多遗留问题。
redleaves 2011-03-11
  • 打赏
  • 举报
回复
你检查一下你所用的pthread库,它导出的函数不是DLL版本的.而你编译thread.cc时引用的却是DLL版.所以符号找不到了.一般网上发布的pthread库有几个不同的导出库,你把mingw里的libpthread.a换成DLL版本的导出库就可以了.
pathuang68 2011-03-10
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 redleaves 的回复:]

楼主可以参考我以前发的帖子

http://topic.csdn.net/u/20090721/23/f57c4e3c-5022-493e-8745-d74b123cce9b.html
[/Quote]
这个很好
加载更多回复(17)

64,678

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧