Imagix 4D User Guide


Variable Flow Between Tasks

Variable Flow Between Tasks reports global and static variables that are used for communication between tasks, detecting uses that are potentially problematic, such as setting or reading variables multiple times.

One of the suspicious uses is the presence of feedback loops. A feedback loop is an interaction between tasks and global variables where a task sets a global variable that is read by the next task. This second task then sets another (or the same) variable that is then read by the next task. This continues until the original task is involved again.

As with the other flow check reports, this analysis does not necessarily indicate a problem, but provides valuable insight for reviewing task interaction. Consider the following code:

int globalA, globalB, globalC, globalD;
int globalE, globalF, globalG;

void taskX() {
    int localX1, localX2 = 1;
    globalA = localX1;
    globalB = localX1;
    globalC = localX1;

    localX2 = globalG;
    globalE = localX2;
}

void taskY() {
    int localY1, localY2 = 1;
    globalA = localY1;
    localY1 = globalB;
    globalC = localY1;

    localY2 = globalE;
    globalF = localY2;
}

In this example, while variables are shared between the tasks, there is no actual feedback loop, as is indicated in the resulting report.

Variable Flow Between Tasks

Key:
        R or RR:          variable is read once (R) or multiple times (RR) in task
        S or SS:          variable is set once (S) or multiple times (SS) in task
        RS or RRSS:       variable is always read before being set in task
        R*:               variable is read first in at least one path; it is set and
                            read in various orders
        S*:               variable is set first in all paths where it is read; it is
                            set and read in various orders thereafter
        Fn or Fn..:       variable and task involved in feedback loop labeled n

Settings:
        Critical Region:                     no critical regions defined
                                             
        No Task Set:                         displayed
        No Task Read:                        displayed
        Single Task Set / Single Task Read:  displayed
        Single Task Set / Multi Task Read:   displayed
        Multi Task Set / Single Task Read:   displayed
        Multi Task Set / Multi Task Read:    displayed
                                             
        Global Variables:                    displayed
        Static Variables:                    displayed
        Struct Container Summary:            omitted
        Union/Bitfield Members:              separate
        Feedback Loops:                      displayed
        Combined Usage Listing:              on

Task Definitions
Tasks are from Auto Task Generation: Any root functions
Name                Members  Graph  Root
autotask 1 - taskX        1    [+]  taskX
autotask 2 - taskY        1    [+]  taskY

Variable                                     Task1     Task2     Task3 ...

                                             autotask 1 - taskX
                                                .      autotask 2 - taskY
---------------------------------------------   =         =      
globalA .....................................   S         S      
    var_flow_simp.c (2)
globalB .....................................   S         R      
    var_flow_simp.c (2)
globalC .....................................   S         S      
    var_flow_simp.c (2)
globalE .....................................   S         R      
    var_flow_simp.c (3)  

Compare that with the following code, where more variables are shared among more tasks, and potential feedback loops exist.

int globalA, globalB, globalC, globalD;
int globalE, globalF, globalG;

void taskV() {
    int localV1 = 1;

    globalD = localV1;
    localV1 = globalD;
}

void taskW() {
    int localW1 = 1;

    globalD = localW1;
    localW1 = globalD;
}

void taskX() {
    int localX1, localX2 = 1;
    globalA = localX1;
    globalB = localX1;
    globalC = localX1;

    localX2 = globalG;
    globalE = localX2;

}

void taskY() {
    int localY1, localY2 = 1;
    globalA = localY1;
    localY1 = globalB;
    globalC = localY1;

    localY2 = globalE;
    globalF = localY2;
}

void taskZ() {
    int localZ2;

    localZ2 = globalF;
    globalG = localZ2;
}

Where potential feedback loops exist in the code, they are displayed in the report, with F(x) used to indicate which task/variable usage corresponds to which feedback loop.

Variable Flow Between Tasks

Key:
        R or RR:          variable is read once (R) or multiple times (RR) in task
        S or SS:          variable is set once (S) or multiple times (SS) in task
        RS or RRSS:       variable is always read before being set in task
        R*:               variable is read first in at least one path; it is set and
                            read in various orders
        S*:               variable is set first in all paths where it is read; it is
                            set and read in various orders thereafter
        Fn or Fn..:       variable and task involved in feedback loop labeled n
        
Settings:
        Critical Region:                     no critical regions defined
                                             
        No Task Set:                         displayed
        No Task Read:                        displayed
        Single Task Set / Single Task Read:  displayed
        Single Task Set / Multi Task Read:   displayed
        Multi Task Set / Single Task Read:   displayed
        Multi Task Set / Multi Task Read:    displayed
                                             
        Global Variables:                    displayed
        Static Variables:                    displayed
        Struct Container Summary:            omitted
        Union/Bitfield Members:              separate
        Feedback Loops:                      displayed
        Combined Usage Listing:              on

Task Definitions
Tasks are from Auto Task Generation: Any root functions
Name                Members  Graph  Root
autotask 1 - taskV        1    [+]  taskV
autotask 2 - taskW        1    [+]  taskW
autotask 3 - taskX        1    [+]  taskX
autotask 4 - taskY        1    [+]  taskY
autotask 5 - taskZ        1    [+]  taskZ

Variable                                     Task1     Task2     Task3 ...

                                             autotask 1 - taskV, autotask 2 - taskW
                                                .      autotask 3 - taskX
                                                .         .      autotask 4 - taskY
                                                .         .         .      autotask 5
---------------------------------------------   =         =         =         =      
globalA .....................................   .         S         S         .      
globalB .....................................   .         S F1      R F1      .      
globalC .....................................   .         S         S         .      
globalD .....................................   SR        .         .         .      
globalE .....................................   .         S F1      R F1      .      

globalF .....................................   .         .         S F1      R F1   
globalG .....................................   .         R F1      .         S F1