taskVarAdd对同一个变量使用了两次

时间:2021-11-18 23:29:16

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

我使用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].

但在某些情况下,使用taskVarAdd()API将相同的全局结构再次添加到同一任务中。 [即,从同一变量的任务中调用taskVarAdd()两次]。

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

此结构将维护该任务的taskID,消息队列ID。

My Questions:

  1. If we call the taskVarAdd() for the same variable twice inside a task, what will be the behavior?
  2. 如果我们在任务内两次调用taskVarAdd()同一个变量,那么行为是什么?

  3. Whether the struct variable added first will be overwritten by the second variable?{I feel this will be overwritten]
  4. 首先添加的struct变量是否会被第二个变量覆盖?{我觉得这会被覆盖]

1 个解决方案

#1


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:

运行测试代码会导致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 ...

使用单个taskVarAdd的相同代码给出预期的结果1 2 3 4 ...

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

PS:您没有指定VxWorks的版本,所以我所说的对Vxworks 6.x有效

#1


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:

运行测试代码会导致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 ...

使用单个taskVarAdd的相同代码给出预期的结果1 2 3 4 ...

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

PS:您没有指定VxWorks的版本,所以我所说的对Vxworks 6.x有效