tags:

views:

35

answers:

2

Hi All,

I have a global struct added to my task using taskVarAdd() API.

But during some scenarios, the same global struct is is added to the same task again using taskVarAdd() API. [i.e., taskVarAdd() is called twice from a task for a same variable].

This struct will maintain the taskID, message queue ids for that task.

My Questions:

  1. If we call the taskVarAdd() for the same variable twice inside a task, what will be the behavior?
  2. Whether the struct variable added first will be overwritten by the second variable?{I feel this will be overwritten]
A: 

The easiest way is to do a simple test case.

int v1;
void tvl()
{
   v1 = 1;
   taskVarAdd(0, &v1);
   v1 = 2;
   taskVarAdd(0, &v1);
   v1 = 3;
   taskDelay(1);
   printf("Initial v1 = %d\n", v1);
   for(;;)
   {
     v1++;
     taskDelay(60);
     printf("v1 = %d\n", v1);
} }

Running the test code results in the following values for v1:

Initial v1 = 2
1 3 3 2 4 4 3 5 5 4...

The same code with a single taskVarAdd gives the expected result of 1 2 3 4 ...

PS: You didn't specify the version of VxWorks, so what I said is valid for Vxworks 6.x

Benoit
Hi Benoit,Thanks For your response. Currently we are using VxWorks 5.5Kindly explain your program? I am not able to understnad the behavior clearly.I have tested your code using tornado and i am getting different results every time i execute your program//1st Attempt-> tv1Inital v1 = V1 = 3V1 = 3V1 = 2V1 = 4V1 = 4V1 = 3V1 = 5V1 = 5V1 = 5V1 = 6//2nd attempt-> tv1Inital v1 = V1 = 1V1 = 3V1 = 4V1 = 2V1 = 4V1 = 5V1 = 3V1 = 5V1 = 6V1 = 4
A: 

Hi Benoit,

Thanks For your response.

Currently we are using VxWorks 5.5

Kindly explain your program? Since i am new to VxWorks, i am not able to understnad the behavior clearly.

I have tested your code using tornado and i am getting different results every time i execute your program

//1st Attempt -> tv1 Inital v1 = V1 = 3 V1 = 3 V1 = 2 V1 = 4 V1 = 4 V1 = 3 V1 = 5 V1 = 5 V1 = 5 V1 = 6

//2nd attempt -> tv1 Inital v1 = V1 = 1 V1 = 3 V1 = 4 V1 = 2 V1 = 4 V1 = 5 V1 = 3 V1 = 5 V1 = 6

But When i commented the second taskVarAdd() and tested it, i am getting the consistent expected results as follows

//1st Attempt -> tv1 Inital v1 = 3 V1 = 4 V1 = 5 V1 = 6 V1 = 7 V1 = 8 V1 = 9 V1 = 10 V1 = 11 V1 = 12 V1 = 13

//2nd Attempt -> tv1 Inital v1 = 3 V1 = 4 V1 = 5 V1 = 6 V1 = 7 V1 = 8 V1 = 9 V1 = 10 V1 = 11 V1 = 12 V1 = 13

My Questions:

  1. Is it right to use two taskVarAdd() inside same task for same variable?
  2. Kindly explain the flow of your program
You can't just go "tv1" from the shell. You have to spawn it: sp(tv1).If you just go-> tv1-> tv1You have added the task var 4 times to the shell's context!
Benoit