【急】多线程运行错误

zhouguoyao 2010-03-04 03:31:21
当只启动1个线程的时候,运行一天都不会报错,
当启动2个以上线程的时候,偶尔会报下面的错误,具体如下:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1502136640 (LWP 31183)]
0x00002b6f86bd5138 in sltstcu () from /opt/oracle/products/11.2.0-beta/db_1/lib/libclntsh.so.11.1
(gdb) where
#0 0x00002b6f86bd5138 in sltstcu () from /opt/oracle/products/11.2.0-beta/db_1/lib/libclntsh.so.11.1
#1 0x00002b6f8816b89e in kpuhhrsp () from /opt/oracle/products/11.2.0-beta/db_1/lib/libclntsh.so.11.1
#2 0x00002b6f8819ab50 in kpuexResPrefRows () from /opt/oracle/products/11.2.0-beta/db_1/lib/libclntsh.so.11.1
#3 0x00002b6f88199cc3 in kpuexec () from /opt/oracle/products/11.2.0-beta/db_1/lib/libclntsh.so.11.1
#4 0x00002b6f88194483 in OCIStmtExecute () from /opt/oracle/products/11.2.0-beta/db_1/lib/libclntsh.so.11.1
#5 0x000000000042237e in otl_cur::exec (this=0xeb94590, iters=0, rowoff=0) at otlv4.h:23546
#6 0x0000000000422c30 in otl_sel::first (this=0xeb94630, cur=@0xeb94590, cur_row=@0xeb9461c, cur_size=@0xeb94620,
row_count=@0xeb94624, eof_data=@0xeb94600, array_size=38) at otlv4.h:24292
#7 0x0000000000422d42 in otl_tmpl_select_cursor<otl_exc, otl_conn, otl_cur, otl_var, otl_sel>::first (this=0xeb94570)
at otlv4.h:6066
#8 0x000000000042951e in otl_tmpl_select_stream<otl_exc, otl_conn, otl_cur, otl_var, otl_sel, otl_datetime>::rewind (
this=0xeb94570) at otlv4.h:6376
#9 0x000000000042996a in otl_tmpl_select_stream (this=0xeb94570, aoverride=0xeac3080, arr_size=38,
sqlstm=0xebb4268 "SELECT COUNT(*) FROM erosa_merge_ctrol", pdb=@0xeac29e8, implicit_select=0, sqlstm_label=0x0) at otlv4.h:6346
#10 0x000000000042c931 in otl_stream::open (this=0xeac2a70, arr_size=38,
sqlstm=0xebb4268 "SELECT COUNT(*) FROM erosa_merge_ctrol", db=@0xeac29e8, ref_cur_placeholder=0x0, sqlstm_label=0x0)
at otlv4.h:29781
#11 0x0000000000415aef in COtlManager::OpenQuery (this=0xeac29e0, szSQL=
{static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x5988b7f0 "hB籠016"}}) at OtlManager.cpp:192
#12 0x0000000000407c28 in CMerge::TestConnected (this=0xeac2810) at merge.cpp:141
#13 0x0000000000408097 in CMerge::RefashOpTime (this=0xeac2810, S_TIME=
{static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x5988c010 "HE籠016"}}, E_TIME=
{static npos = 18446744073709551615, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x5988c000 "\210x篭016"}}) at merge.cpp:642
#14 0x000000000040a5ea in CMerge::OnPre (this=0xeac2810) at merge.cpp:608
#15 0x000000000040d0c5 in CMerge::run (this=0xeac2810, lparam=0x0) at merge.cpp:536
#16 0x0000000000434859 in CThread::thread_func (param=0xeac2828) at Thread.cpp:43
#17 0x00000035f82062f7 in start_thread () from /lib64/libpthread.so.0
#18 0x00000035f76d1b6d in clone () from /lib64/libc.so.6
(gdb) info threads
3 Thread 1921571136 (LWP 31186) otl_column_desc (this=0x2aaaac012550) at otlv4.h:1742
* 2 Thread 1502136640 (LWP 31183) 0x00002b6f86bd5138 in sltstcu ()
from /opt/oracle/products/11.2.0-beta/db_1/lib/libclntsh.so.11.1
1 Thread 47758043154736 (LWP 31174) 0x00000035f7698341 in nanosleep () from /lib64/libc.so.6
...全文
264 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouguoyao 2010-03-05
  • 打赏
  • 举报
回复
楼上的 最后是怎么解决的,谢谢
macrojj 2010-03-05
  • 打赏
  • 举报
回复
我遇到的多线程 错误都是一会就报了
不过偶然的报一次。。。。

zhouguoyao 2010-03-05
  • 打赏
  • 举报
回复
有谁遇到过类似的错误

cattycat 2010-03-04
  • 打赏
  • 举报
回复
通常连接数据库只有一次,初始化的时候连接数据库,成功后,在线程函数只要用这个连接去查询得到ResultSet等,线程退出后关闭connection,这个connection不是刚开始的用URL连接数据库。
zhouguoyao 2010-03-04
  • 打赏
  • 举报
回复
谢谢各位,代码太多了,不方便贴

数据库连接每个线程都是用自己的连接的

逻辑是这样,比如类A,有个函数B完成一个功能(里面包括数据库连接,查询、更新等)
而类A初始化的时候创建一个线程调用函数B

我在主函数main中,如果只生成一个类A的对象,则只有一个线程,不会报错。
如果在主函数main中,生成多个类A的对象,则会对应生成对个线程,就偶然会报错。

main()-->类A-->创建线程-->调用类自己的函数B(其中数据库连接等资源都是类A自己的)

cattycat 2010-03-04
  • 打赏
  • 举报
回复
1个数据库的连接不能在多个线程中用吧,资源访问冲突了,有可能是,得保证互斥。
s446721902 2010-03-04
  • 打赏
  • 举报
回复
多线程又是偶尔报错的查下共用资源吧
SiGoYi 2010-03-04
  • 打赏
  • 举报
回复
看看你代码里有没有两个线程共用的资源,或代码段,如果有需要加锁,以避免访问冲突。
ThinkInAI 2010-03-04
  • 打赏
  • 举报
回复
段错误。

指针访问非法,应该是2个线程相互资源冲突了
SiGoYi 2010-03-04
  • 打赏
  • 举报
回复
楼主能不能把一些主要代码帖出来啊!光看你的错误就只能帮你顶了~~~~~~~~~
zhouguoyao 2010-03-04
  • 打赏
  • 举报
回复
上面为GDB调试的错误信息

64,637

社区成员

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

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