嘿家伙。我的程序在几个部分使用OpenMP来执行多线程。它适用于大部分,但偶尔会摊位,只是坐在那里。所以我在调试器中运行它,并且找到它正在拖延的区域。然后我尝试检查当前的变量,我得到这个:用gdb调试多线程代码但不能访问私有变量?
169 if(0<=myPtr[3] && myPtr[3]<=1){//Reassign the velocities.
(gdb) print myPtr[3]
No symbol "myPtr" in current context.
我不知道这是为什么。当它只有单线程时,我可以打印它。我私有化了这个变量,并且我想象程序不会知道当我要求它打印什么的时候我指的是哪个线程(即使这个http://cc.jct.ac.il/cc-res/online-doc/gdb/gdb_26.html#SEC26说总会有一个当前线程..?)。所以,如果我选择一个线程,我得到相同的东西:
(gdb) info threads
3 process 32970 thread 0x4203 0x90f9846e in __semwait_signal()
2 process 32970 thread 0x3007 0x90f9846e in __semwait_signal()
* 1 process 32970 local thread 0x2e03 mover3dsurfaces (.omp_data_i=0xbffff030) at mover3dsurfaces.cpp:174
(gdb) thread 1
[Switching to thread 1 (process 32970 local thread 0x2e03)]
mover3dsurfaces (.omp_data_i=0xbffff030) at mover3dsurfaces.cpp:174
174 partList.velocity(i,3) = velPtr[2];
(gdb) print velPtr[1]
No symbol "velPtr" in current context.
我实际上有点困惑这部分。我的机器只有两个处理器。如何有3个线程?我发现__semwait_signal()之前的两个十六进制数字是相同的,但我不知道它们为什么会分裂。我如何查看单个线程的变量?
谢谢!
版本:迈耶:戴克澜〜$ GDB -v GNU GDB 6.3.50-20050815(苹果版GDB-966) 和我用选项-ggdb编译。在一个测试程序中,我使用OpenMP进行循环,并显示每个迭代所在的当前线程。它只产生了两个循环。在这里,我也没有指定要创建的线程数,那么为什么要选择三个呢?另外,仅仅为了重申,当它不是多线程时,我可以做的很好。我可以打印任何我想要的变量。 – MasterZibZob 2010-08-13 00:51:57