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


Tutorials



FORK JOIN CONTROL

Fork And Join Control:


Wait_chiled():



The wait_child() system task is used to ensure that all child processes are executed before the Vera program terminates.


EXAMPLE : without wait_var

task me () {
integer n ;

for(n=0; n<10 ; n++) {
fork
{delay(10)
printf(" inside for.join none ,time = %0d \n",get_time(LO) ) ;
}
join none
}
// wait_child() ;
printf(" END of task \n");
}

program main {
me() ;
printf(" END of program \n");
}

RESULTS

END of task
END of program



The soluton shows that inside forkjoin state ments are not printed.


EXAMPLE : with wait_var

task me () {
integer n ;

for(n=0; n<10 ; n++) {
fork
{delay(10)
printf(" inside for.join none ,time = %0d \n",get_time(LO) ) ;
}
join none
}
wait_child() ;
printf(" END of task \n");
}

program main {
me() ;
printf(" END of program \n");
}

RESULTS

inside for.join none ,time = 10
inside for.join none ,time = 10
inside for.join none ,time = 10
inside for.join none ,time = 10
inside for.join none ,time = 10
inside for.join none ,time = 10
inside for.join none ,time = 10
inside for.join none ,time = 10
inside for.join none ,time = 10
inside for.join none ,time = 10
END of task
END of program

Terminate:



The terminate statement terminates all active descendants of the current thread in which it was called.If any of the child processes have other descendants, the terminate command terminates them as well.
This example forks off several child processes within a task. After any of the child processes is complete, the code continues to execute. Before the task is completed, all remaining child processes are terminated.


EXAMPLE : without terminate


task task1() {
delay(10);
printf(" before fork time = %d \n",get_time(LO) );
fork {
delay (20);
printf("time = %d delay 20\n ",get_time(LO) );
}
{
delay(10);
printf("time = %d delay 10\n ",get_time(LO) );
}
{
delay(5);
printf("time = %d delay 5\n ",get_time(LO) );
}
join any


fork {
delay(35);
printf("time = %d delay 35\n ",get_time(LO) );
}
{ delay(25)
printf("time = %d delay 25\n ",get_time(LO) );
}
{delay(15)
printf("time = %d delay 15\n ",get_time(LO) );
}
join none
// terminate;
delay(100);
}

program main {
task1();
printf(" Time = %d Task completed \n",get_time(LO) );
}

RESULTS

before fork time = 10
time = 15 delay 5
time = 20 delay 10
time = 30 delay 20
time = 30 delay 15
time = 40 delay 25
time = 50 delay 35
Time = 115 Task completed



EXAMPLE : with terminate


task task1() {
delay(10);
printf(" before fork time = %d \n",get_time(LO) );
fork {
delay (20);
printf("time = %d delay 20\n ",get_time(LO) );
}
{
delay(10);
printf("time = %d delay 10\n ",get_time(LO) );
}
{
delay(5);
printf("time = %d delay 5\n ",get_time(LO) );
}
join any


fork {
delay(35);
printf("time = %d delay 35\n ",get_time(LO) );
}
{ delay(25)
printf("time = %d delay 25\n ",get_time(LO) );
}
{delay(15)
printf("time = %d delay 15\n ",get_time(LO) );
}
join none
terminate;
delay(100);
}

program main {
task1();
printf(" Time = %d Task completed \n",get_time(LO) );
}

RESULTS

before fork time = 10
time = 15 delay 5
Time = 115 Task completed



Both the solutions ahow that the task is completed at time 115 .When teriminate is not used, all the chaild process execute,when teriminate is use,all the chaild processes are teriminated.


Suspend_thread:



The suspend_thread() system task is used to temporarily suspend the current thread.It suspends the current thread and allows other ready concurrent threads to run. When all ready threads have had one chance to block, the suspended thread resumes execution.


EXAMPLE : without suspend_thread


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);
printf( " Suspending the thread \n");
// suspend_thread();
printf( " After Suspending the thread \n");
printf(" time = %0d: i is %0d \n",get_time(LO),i);

}
join none
}
}


RESULTS

time = 20: i is 0
Suspending the thread
After Suspending the thread
time = 20: i is 0
time = 20: i is 1
Suspending the thread
After Suspending the thread
time = 20: i is 1
time = 20: i is 2
Suspending the thread
After Suspending the thread
time = 20: i is 2
END OF SIMUALTION



EXAMPLE : with suspend_thread


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);
printf( " Suspending the thread \n");
suspend_thread();
printf( " After Suspending the thread \n");
printf(" time = %0d: i is %0d \n",get_time(LO),i);

}
join none
}
}


RESULTS

time = 20: i is 0
Suspending the thread
time = 20: i is 1
Suspending the thread
time = 20: i is 2
Suspending the thread
After Suspending the thread
time = 20: i is 0
After Suspending the thread
time = 20: i is 1
After Suspending the thread
time = 20: i is 2
END OF SIMUALTION



The solution shows that all the child threads are suspended until all the calls are made and then reumed.
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