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


Tutorials



FORK JOIN

Fork Join:



Fork/join blocks provide the primary mechanism for creating concurrent processes.The all | any | none options specify when the code after the fork/join block executes.The default is all.

all :: The default is all. Code after the block executes after all of the concurrent processes are completed.
any :: When any is used, code after the block executes after any single concurrent process is completed.
none :: When none is used, code after the block executes immediately, without waiting for any of the processes to complete.






EXAMPLE : fork/join none

program main {
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 none
printf(" time = %d Outside the main fork \n",get_time(LO) );
delay(40);
}
RESULTS

BEFORE fork time = 10
time = 10 Outside the main fork
time = 15 delay 5
time = 20 delay 10
time = 30 delay 20


EXAMPLE : fork/join any


program main {

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
printf(" time = %d Outside the main fork \n",get_time(LO) );
delay(40);
}
RESULTS

BEFORE fork time = 10
time = 15 delay 5
time = 15 Outside the main fork
time = 20 delay 10
time = 30 delay 20


EXAMPLE : fork/join all

program main {

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 all
printf(" time = %d Outside the main fork \n",get_time(LO) );
delay(40);
}

RESULTS

BEFORE fork time = 10
time = 15 delay 5
time = 20 delay 10
time = 30 delay 20
time = 30 Outside the main fork



When defining a fork/join block, encapsulating the entire fork inside braces ({}) results in the entire block being treated as a single thread, and the code executes consecutively.


EXAMPLE : sequential statement in fork/join

program main {
delay(10);

printf(" First fork time = %d \n",get_time(LO) );
fork {
delay (20);
printf("time = %d delay 20 \n ",get_time(LO),i);
}
{
delay(10);
printf("time = %d delay 10 \n ",get_time(LO),j);
}
{
delay(5);
printf("time = %d delay 5 \n ",get_time(LO),m);
delay(2);
printf("time = %d delay 2 \n ",get_time(LO),m);

}
join any
printf(" time = %d Outside the main fork \n",get_time(LO) );

delay(40);
}

RESULTS

First fork time = 10
time = 15 delay 5
time = 17 delay 2
time = 17 Outside the main fork
time = 20 delay 10
time = 30 delay 20
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