[英]What are the resource dependencies for a thread in a process?
我编写了一个 C++ 代码,它在一个进程中创建了 n 个线程。 它在创建的线程数为 6 或小于 6 时起作用,当我尝试创建 7 个线程时,进程崩溃。 造成这种情况的原因是什么? 创建 6 个线程时在我的进程中的线程数- 7
堆栈大小16384
允许的最大线程数- 6787
我用来创建线程的代码片段:
pthread_t *thread; int iret1; uint8_t i; char commandBuffer[8192];
if(argc <=1)
{
DEBUG("pass rasp system id\n");
return -1;
}
DEBUG("SETTING SYSTEM TIME\n");
system("sudo date -s \"$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z\"");
DEBUG("Initializing wiring pi\n");
wiringPiSetup();
usleep(1000000);
DEBUG("Initialized wiring pi\n");
thread = (pthread_t*)malloc(sizeof(pthread_t)*TOTAL_I2CBUSLINES);
if (thread == NULL)
{
DEBUG("out of memory\n");
exit(EXIT_FAILURE);
}
/* Create independent threads each of which will execute function */
for(i = 0; i < TOTAL_I2CBUSLINES;i++)
{
iret1 = pthread_create( &thread[i], NULL, ina219Read_thread_func, (void*) &gdc[i]);
if(iret1)
{
fprintf(stderr,"Error - pthread_create() return code: %d\n",iret1);
exit(EXIT_FAILURE);
}
DEBUG("\nSuccesfully created I2C line for: %d", i);
}
您正在使用两个数组“线程”和“gdc”。 查看它们的索引是否超出范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.