malloc - Vxworks getting stuck in memory routines -


i'm running vxworks 6.3 , have run problem. have series of tasks running in rtp. create task, stuff destroy task. create 2 tasks, close together, stuff , destroy them. these tasks have crazy things like, malloc , free memory. unfortunately, if enough times, 1 of tasks stuck in memory (both malloc , free) routines on semaphore. it's second task gets "lost" @ start of task in either free or malloc. after failure, can still create tasks , can still malloc memory. failing task sits forever, waiting semaphore... semaphore other tasks must using.

does have idea how task can stuck in memory routines?

0x08265e58 malloc       +0x2c : 0x082416f4 () 0x08267e50 mempartalloc +0x28 : 0x08241734 () 0x08267e0c mempartalignedalloc+0x70 : 0x08267c04 () 0x08267c7c mempartfree  +0xfc : 0x08240654 () 0x082753c0 semtake      +0x90 : 0x08242534 () 0x082752ec semumtake    +0xd8 : 0x08242514 () ---- system call boundary ----  -> tw 0x69d21b0   name       entry       tid       status   delay  obj_type    obj_id   obj_name ---------- ---------- ---------- ---------- ----- ---------- ---------- -------- thttp631-2  0x827dbfc  0x69d21b0 pend           0 sem_m       0x6859650 n/a  semaphore id        : 0x6859650 semaphore type      : mutex task queuing        : priority pended tasks        : 1 owner               : 0x69d1a08    deleted! options             : 0xd       sem_q_priority                                 sem_delete_safe                                 sem_inversion_safe vxworks events -------------- registered task     : none event(s) send    : n/a options             : n/a pended tasks ------------    name      tid    pri timeout ---------- -------- --- ------- thttp631-25502 69d21b0 120       0 value = 0 = 0x0 -> 

it recommended allocate enough memory worst case @ init time, , re-use memory throughout duration of program. if have real time requirements malloc/free non-deterministic operations, recommend re-using tasks rather recreating new tasks @ runtime, use semaphore or msgqueue kick off appropriate tasks @ appropriate times. program flow might this:

inittime() {     t1mem = malloc(t1memsize);     t2mem = malloc(t2memsize);     t3mem = malloc(t3memsize);     t1q = msgqcreate(qlen, msglen, msg_q_fifo);     t2q = msgqcreate(qlen, msglen, msg_q_fifo);     t3q = msgqcreate(qlen, msglen, msg_q_fifo);     rspq = msgqcreate(qlen, msglen, msg_q_fifo);     taskspawn("t1", t1pri, ..., t1entry, t1mem, t1q, rspq, ...);     taskspawn("t2", t2pri, ..., t2entry, t2mem, t2q, rspq, ...);     taskspawn("t3", t3pri, ..., t3entry, t3mem, t3q, rspq, ...);      runtime(t1sem, t2sem, t3sem, rspq);      msgqdelete(t1q);     msgqdelete(t2q);     msgqdelete(t3q);     msgqdelete(rspq);     free(t1mem);     free(t2mem);     free(t3mem); }  runtime(msg_q_id t1q, msg_q_id t2q, msg_q_id t3q, msg_q_id rspq) {     while (programrun)     {         tasksdone = 0;         msgqsend(t1q, t1start, msglen, 100, msg_pri_normal);         if (msgqreceive(rspq, buf, msglen, errorcasetimeout) == ok)         {             // check make sure msg t1done...              // report error if isn't...             msgqsend(t2q, t2start, msglen, 100, msg_pri_normal);             msgqsend(t3q, t3start, msglen, 100, msg_pri_normal);             (int x = 0; x < 2; x++)             {                 if (msgqreceive(rspq, buf, msglen, errorcasetimeout) == ok)                 {                      // check make sure msg t2done/t3done...                       // report error if isn't...                      tasksdone++;                 }             }         }         if (tasksdone == 2)         {              // good... keep on running...         }         else         {              // task didnt finish within errorcasetimeout time...              // report error or something, maybe set programrun false...          }     } }  t1entry(void* mem, msg_q_id q, msg_q_id rspq) {     while (programrun)     {         if (msgqreceive(q, buf, msglen, 100) == ok)         {             dotask1(mem);             msgqsend(rspq, t1done, msglen, 100, msg_pri_normal);         }     } }  t2entry(void* mem, msg_q_id q, msg_q_id rspq) {     while (programrun)     {         if (msgqreceive(q, buf, msglen, 100) == ok)         {             dotask2(mem);             msgqsend(rspq, t2done, msglen, 100, msg_pri_normal);         }     } }  t3entry(void* mem, msg_q_id q, msg_q_id rspq) {     while (programrun)     {         if (msgqreceive(q, buf, msglen, 100) == ok)         {             dotask3(mem);             msgqsend(rspq, t3done, msglen, 100, msg_pri_normal);         }     } } 

obviously above code not dry, , not error cases handled, start , has chance of working deterministically.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -