首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >进程中线程的资源依赖关系是什么?

进程中线程的资源依赖关系是什么?
EN

Stack Overflow用户
提问于 2019-12-11 14:52:12
回答 1查看 85关注 0票数 0

我已经编写了一段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.

我用来创建线程的代码片段:

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

发布于 2019-12-11 18:49:44

您正在使用两个数组'thread‘和'gdc’。看看他们的索引是否超出了界限。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59280245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档