tags:

views:

100

answers:

1

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

Following is the sample program witten by Benoit to explain the scenario,

int v1;

void tvl()

{

int i = 0;

v1 = 1;

taskVarAdd(0, &v1);

v1 = 2;

taskVarAdd(0, &v1);

v1 = 3;

taskDelay(1);

printf("Initial v1 = %d\n", v1);

for(i = 0;i<10;i++)

{

 v1++;

 taskDelay(60);

 printf("v1 = %d\n", v1);

}

}

When I tested the 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

We are using VxWork 5.5

My Questions:

  1. Is it right to use two taskVarAdd() inside same task for same variable?

  2. What will be the behavior if two taskVarAdd() is used for same variable inside same task?

  3. Kindly explain the flow of your program

+1  A: 

I'd like to say it is not right to add taskVarAdd two times:

  1. first, the vxworks's implementation did not deal with this situation.(I checked the vxworks source, when two taskvar have the same address, the taskVar will set two times which will get the value wrong. As vxworks is close source, so I am not going to paste the source here, but it's the vxworks' implementation makes it wrong)

  2. second, why you need to add two times? taskAddVar make a address to be private to current task, when the task is switch out, the value be saved to task's TCB; and when the task is switch back, the private address's value will be copied back. So different task will have different value even in the same address.

  3. vxworks implements the taskVar mechanism by adding a switch hook to make a task's private var to be save/set at task switch, which make same routine but run in different task context can have different private value at same address.

arsane