QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1585|回复: 0

请教, 如何让std::vector线程安全

[复制链接]
发表于 2006-3-11 00:34:14 | 显示全部楼层 |阅读模式
我尝试着写个bt的client, 但是在多线程访问vector时中对象时,总是报些稀奇古怪的错误。

下面是其中之一。
----------
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1306031184 (LWP 5630)]
0xb7b8cb23 in memmove () from /lib/libc.so.6
Current language:  auto; currently c
(gdb) bt
#0  0xb7b8cb23 in memmove () from /lib/libc.so.6
#1  0x0805dd52 in std::vector<ChunkDownloader*, std::allocator<ChunkDownloader*> >::erase (this=0x809d3e at stl_algobase.h:258
#2  0x0805dc08 in PieceDownloader::run (this=0x809d33
    at PieceDownloader.cpp:165
#3  0xb7ed7be4 in ccxx_exec_handler (th=0x809d33 at thread.cpp:1117
#4  0xb7c443dd in start_thread (arg=0xb2278bb0) at pthread_create.c:261
#5  0xb7bdcc6e in clone () from /lib/libc.so.6
-------
下面的一个(更奇怪了, 在 getOffset中竟然会错):
-------
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1306465360 (LWP 5653)]
0x0805d71d in PieceDownloader::run (this=0x809cc30) at ChunkDownloader.h:53
53        unsigned int getOffset(){return offset;};
Current language:  auto; currently c++
(gdb) bt
#0  0x0805d71d in PieceDownloader::run (this=0x809cc30) at ChunkDownloader.h:53
#1  0xb7e6dbe4 in ccxx_exec_handler (th=0x809cc30) at thread.cpp:1117
#2  0xb7bda3dd in start_thread (arg=0xb220ebb0) at pthread_create.c:261
#3  0xb7b72c6e in clone () from /lib/libc.so.6
------
由于本人是第一次用C++来写程序, 哪位帮忙指点一下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-2 20:25 , Processed in 0.106010 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表