我已经编写了一段C++代码,它在一个进程中创建n个线程。当创建的线程数为6或少于6时,它可以工作,当我尝试创建7个线程时,进程崩溃。原因是什么?The number of threads when in my process when 6 threads are created -7
Stack size 16384
Maximum Threads allowed - 6787
Running threads including 7 spawned by my process - 91
Error that occurs when I try to create 7 threads.
我用来创建线程的代码片段:
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);
}发布于 2019-12-11 18:49:44
您正在使用两个数组'thread‘和'gdc’。看看他们的索引是否超出了界限。
https://stackoverflow.com/questions/59280245
复制相似问题