Title |
QNX2 program periodically stops. |
Ref. No. |
QNX.000009321 |
Category(ies) |
Utilities, Development |
Issue |
I'm struggling with a QNX2 program that runs for a period of time and then dies. Here's a snippet of code that demonstrates my problem:
for(;;) { x09vtid=name_locate(CLRHOUSE, "othertask", SIZE); x09if(vtid == 0) x09{ x09x09printf("Name locate failed!n"); x09x09exit(0); x09} x09send(vtid, MSG, REPLY_MSG, sizeof(MSG)); } This fails after running for a while even when the "othertask" name is still registered!
|
Solution |
Your program is failing because it's exhausting system resources. With your present approach, an additional virtual circuit (VC) is being created every time name_locate() is called. Because each VC takes up one entry in the process table, repeatedly creating VCs in this way can soon take up all available entries (in QNX2, the table contains 150 or 254 entries, depending on which version of the OS you're using).
The best way out of this problem? Do the name_locate() once, outside the loop, and then use the returned VC for all future sends:
vtid=name_locate(CLRHOUSE, "othertask", SIZE); x09if(vtid==0) x09{ x09x09printf("Name locate failed!n"); x09x09exit(0); x09} for(;;) { x09send(vtid, MSG, REPLY_MSG, sizeof(MSG)); } x09OR vtid=0; for(;;) { x09if (vtid!=0) vc_release(vtid); /** Don't accumulate VCs! {**/ x09vtid=name_locate(CLRHOUSE, "othertask", SIZE); x09if(vtid==0) x09{ x09x09printf("Name locate falled!n"); x09x09exit(0); x09} x09send(vtid, MSG, REPLY_MSG, sizeof(MSG)); }
Note that releasing VCs once they're used also works, but this incurs much more processing overhead and will degrade performance.
By the way, you could also experience this situation in QNX4. The only difference lies in the names of the functions used (e.g. qnx_name_locate instead of name_locate).
|
|