免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3549 | 回复: 2

一个map赋值却有时阻塞的问题。 [复制链接]

论坛徽章:
0
发表于 2009-04-28 09:20 |显示全部楼层
我有一个程序在运行时需要初始化一个map,但程序却在map的第一个赋值处阻塞,很不解,下面是调试过程。
比如该程序的进程号为12345
#strace -p 12345
Process 23524 attached - interrupt to quit


只返回这一行结果。

又通过gdb attach到该进程得到如下结果:


  1. (gdb) attach 12345
  2. ... (中间省略了,只输出最后一句)
  3. 0x08072787 in std::less<int>::operator() (this=0x80a1f44, __x=@0x80a1f54, __y=@0xbfae9d44)
  4.     at /usr/lib/gcc/i386-redhat-linux/4.1.0/../../../../include/c++/4.1.0/bits/stl_function.h:227
  5. 227           { return __x < __y; }
  6. (gdb) bt
  7. #0  0x08072787 in std::less<int>::operator() (this=0x80a1f44, __x=@0x80a1f54, __y=@0xbfae9d44)
  8.     at /usr/lib/gcc/i386-redhat-linux/4.1.0/../../../../include/c++/4.1.0/bits/stl_function.h:227
  9. #1  0x080738bf in std::_Rb_tree<int, std::pair<int const, std::string>, std::_Select1st<std::pair<int const, std::string> >, std::less<int>, std::allocator<std::pair<int const, std::string> > >::lower_bound (this=0x80a1f44, __k=@0xbfae9d44)
  10.     at /usr/lib/gcc/i386-redhat-linux/4.1.0/../../../../include/c++/4.1.0/bits/stl_tree.h:1371
  11. #2  0x0807392d in std::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > >::lower_bound (this=0x80a1f44, __x=@0xbfae9d44) at /usr/lib/gcc/i386-redhat-linux/4.1.0/../../../../include/c++/4.1.0/bits/stl_map.h:576
  12. #3  0x08074da0 in std::map<int, std::string, std::less<int>, std::allocator<std::pair<int const, std::string> > >::operator[] (this=0x80a1f44, __k=@0xbfae9d44) at /usr/lib/gcc/i386-redhat-linux/4.1.0/../../../../include/c++/4.1.0/bits/stl_map.h:345
  13. #4  0x080686f2 in Student::initIdName (this=0x80a1e40) at Student.cpp:213
  14. #5  0x0806598c in main (argc=2, argv=0xbfae9ee4) at Main.cpp:56

  15. 确定了最终阻塞的位置是:
  16. stl_function.h文件中:
  17. template <class _Tp>
  18. struct less : public binary_function<_Tp, _Tp, bool>
  19. {  
  20.   bool
  21.   operator()(const _Tp& __x, const _Tp& __y) const
  22.   { return __x < __y; }       // <=======阻塞在这行
  23. };
复制代码


我map的键从一个比较大的数开始,比如8000,我想跟这个应该没关系吧。没读过map的实现源码,不敢定论,抽时间看一下。
因为我这个程序编译的时候连接了一些动态库和静态库,会不会在静态库重新编译后,我的.o文件有的重新连接而有的没重新连接使得影响了一些变量的地址,但为什么会在一个比较语句处阻塞呢?

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:172015亚冠之水原三星
日期:2015-06-02 16:34:202015年亚冠纪念徽章
日期:2015-10-19 18:13:37程序设计版块每日发帖之星
日期:2015-11-08 06:20:00
发表于 2009-04-28 09:29 |显示全部楼层
很奇怪,只听说过系统调用能阻塞

论坛徽章:
0
发表于 2009-04-28 09:36 |显示全部楼层
有时死循环的特征也是阻塞~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP