|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



SHADOW VARIABLES

Shadow Variables



By default, all child processes have access to the parent´s variables.However, if multiple processes independently use the same variable,races can occur. To avoid races within fork/join blocks, shadow variables should be used.


EXAMPLE : without shadow variable

program main {
call();
delay(40);
printf(" END OF SIMUALTION \n");
}

task call(){
integer i;
delay(10);
for(i = 0; i < 3; i++) {
fork
{
delay(10);
printf(" time = %0d: i is %0d \n",get_time(LO),i);
}
join none
}
}


RESULTS

time = 20: i is 3
time = 20: i is 3
time = 20: i is 3
END OF SIMUALTION



Look at the solution, i is 3 in all the threads.


EXAMPLE :with shadow variable

program main {
call();
delay(40);
printf(" END OF SIMUALTION \n");
}

task call(){
shadow integer i; // using shadow variable
delay(10);
for(i = 0; i < 3; i++) {
fork
{
delay(10);
printf(" time = %0d: i is %0d \n",get_time(LO),i);
}
join none
}
}


RESULTS

time = 20: i is 0
time = 20: i is 1
time = 20: i is 2
END OF SIMUALTION



The solution shows that ,Using the shadow keyword forces the Vera compiler to create a copy of the variable i local to each child process, which eliminates race conditions. Any descendants of the child processes will also have a copy of the variable local to that descendant.
Index
Introduction
Data Types
Linked List
Operators Part 1
Operators Part 2
Operators Part 3
Operator Precedence
Control Statements
Procedures And Methods
Interprocess
Fork Join
Shadow Variables
Fork Join Control
Wait Var
Event Sync
Event Trigger
Semaphore
Regions
Mailbox
Timeouts
Oop
Casting
Randomization
Randomization Methods
Constraint Block
Constraint Expression
Variable Ordaring
Aop
Predefined Methods
String Methods
Queue Methods
Dut Communication
Functional Coverage

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer