[英]Segmentation fault during pthread_join
#define SIZE 3
#define MAX_THREADS 9
int main() {
...
pthread_t m_threads[MAX_THREADS];
int t_num = 0;
for (int i = 0; i < SIZE; ++i) {
for (int j = 0; j < SIZE; ++j) {
...
pthread_create(&m_threads[i], NULL, multiply, (void *) &td[t_num]);
t_num++;
}
}
for( int i = 0; i < MAX_THREADS; i++ ) {
pthread_join(m_threads[i], NULL);
}
return 0;
}
I am creating 9 threads to do some matrix multiplication.我正在创建 9 个线程来进行一些矩阵乘法。 The calculations are successful.计算成功。 But the program crashes when I try to join the threads.但是当我尝试加入线程时程序崩溃了。 The program crashes while performing pthread_join(m_threads[i], NULL)
during the 4th iteration of the for-loop.在 for 循环的第 4 次迭代期间执行pthread_join(m_threads[i], NULL)
时程序崩溃。
Debugging the program I get this segmentation fault from GDB.调试程序我从 GDB 得到这个分段错误。
Thread 1 "Pthread" received signal SIGSEGV, Segmentation fault.
0x00007f7d0063ac9f in __free_tcb () from /lib/x86_64-linux-gnu/libpthread.so.0
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
将pthread_create(&m_threads[i]
修改为pthread_create(&m_threads[t_num]
解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.