malloc_consolidate创建新线程时出错

时间:2013-04-10 13:11:16

标签: c++ multithreading memory operating-system

我正在尝试创建一个管理简单线程的程序。 这是主要计划:

int main(int argc, char **argv)
{
  printf("test2:\n--------------\n");
  clock_t stop1;

  uthread_init(100);
  printf ("***%d***\n",uthread_get_tid());
  if(uthread_spawn(f1)==-1)
        printf("FAIL: uthread_spawn failure\n");

  stop1 = clock () + 0.05 * CLOCKS_PER_SEC;
  int i;    
  printf ("StartLoop of thread: ***%d***\n",uthread_get_tid());
  while(clock ()<stop1) {
    for(i=0;i<10000000;i++) {}
  }
  printf ("FinishLoop of thread: ***%d***\n",uthread_get_tid());

  uthread_terminate(0);
  return 0;
}

代码正在创建新线程,然后创建一个新线程,然后创建一个新线程。在创建3的三分之一时,我得到了错误。 程序停留在这里(在创建线程函数中):

int uthread_spawn(void (*f)(void)) {
DBG(("Spawning !"))
        //checking if number of threads is bigger then max
if (getThreadCount() > MAX_THREAD_NUM){
    errmsgLibrary(MAX_THREADS_LIM);
    return FAIL;
}

// TODO - Check if needed to block/unblock here
if (blockTimerSignal(BLOCK) == SUCCESS){
    DBG(("Block signal success"))
    DBG(("ntid value: %d",nTid))
    pThread t = new Thread(f,nTid++);
    DBG(("new thread created"))
    t->setState(Thread::READY);
    ready.push_back(t);
    DBG(("Added new Thread - %d",(nTid-1)))
    DBG(("Number of threads in ready list is  - %d",(ready.size())))
    blockTimerSignal(UNBLOCK);
    return (nTid-1);
}
DBG(("Block signal not success"))
return FAIL;
}

尝试创建新的Thread()。

我得到的错误是:

test02-new: malloc.c:5161: malloc_consolidate: Assertion `p->fd_nextsize->bk_nextsize == p' failed.
Abort

0 个答案:

没有答案