|
|
|
|
|
|
|
|
|
|
|
|
Introduction
|
|
|
Vera supports features to help model parallel, independent activities. We will be covering following features of Vera language. |
|
|
|
|
|
- fork - join
- wait_var()
- event methods
- semaphores
- region
- mailboxes
- timeouts
|
|
|
|
|
|
fork join
|
|
|
fork join is basic construct in Vera for executing code in parallel. THis is same as fork and join in Verilog with more advance control. |
|
|
|
|
|
Syntax : fork-join |
|
|
|
|
|
fork
{
statement1;
}
{
statement2;
}
...
{
statementN;
}
join [all | any | none]
|
|
|
|
|
|
Below Table shows the details of all join |
|
|
|
|
|
join
|
Description
|
all
|
This is default. 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
|
|
|
|
|
|
1 program fork_join {
2 integer thread1 = 1;
3 integer thread2 = 2;
4 integer thread3 = 3;
5 printf("----------JOIN ALL---------\n");
6 fork
7 {
8 delay(400) ;
9 printf("[%0d] thread=%0d\n", get_time(LO),thread1);
10 }
11 {
12 delay(200) ;
13 printf("[%0d] thread=%0d\n", get_time(LO), thread2);
14 }
15 {
16 delay(100) ;
17 printf("[%0d] thread=%0d\n", get_time(LO), thread3);
18 }
19 join all
20 printf("[%0d] After join all\n", get_time(LO) );
21 printf("----------JOIN ANY---------\n");
22 fork
23 {
24 delay(400) ;
25 printf("[%0d] thread=%0d\n", get_time(LO),thread1);
26 }
27 {
28 delay(200) ;
29 printf("[%0d] thread=%0d\n", get_time(LO), thread2);
30 }
31 {
32 delay(100) ;
33 printf("[%0d] thread=%0d\n", get_time(LO), thread3);
34 }
35 join any
36 printf("[%0d] After join any\n", get_time(LO) );
37 delay (400);
38 printf("----------JOIN NONE---------\n");
39 fork
40 {
41 delay(400) ;
42 printf("[%0d] thread=%0d\n", get_time(LO),thread1);
43 }
44 {
45 delay(200) ;
46 printf("[%0d] thread=%0d\n", get_time(LO), thread2);
47 }
48 {
49 delay(100) ;
50 printf("[%0d] thread=%0d\n", get_time(LO), thread3);
51 }
52 join none
53 printf("[%0d] After join none\n", get_time(LO) );
54 delay (400);
55 printf("[%0d] End of program\n", get_time(LO) ) ;
56 }
You could download file fork_join.vr here
|
|
|
|
|
|
|
|
|
|
|
|
Simulation : fork join
|
|
|
|
|
|
----------JOIN ALL---------
[100] thread=3
[200] thread=2
[400] thread=1
[400] After join all
----------JOIN ANY---------
[500] thread=3
[500] After join any
[600] thread=2
[800] thread=1
----------JOIN NONE---------
[900] After join none
[1000] thread=3
[1100] thread=2
[1300] End of program
|
|
|
|
|
|
Shadow Variable
|
|
|
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. |
|
|
|
|
|
- A variable cannot be declared as a shadow variable in a task or function's formal argument list.
- Shadow variables cannot be declared in a global context.
|
|
|
|
|
|
Example : shadow variable
|
|
|
|
|
|
1 program shadow_variable {
2 spawn_process() ;
3 delay(100) ;
4 spawn_process_with_shawdow();
5 delay(100) ;
6 }
7
8 task print(integer i) {
9 printf(" n = %0d\n", i);
10 }
11
12 task spawn_process () {
13 integer n;
14 printf("In spawn_process\n");
15 for(n=0; n<3 ; n++) {
16 fork
17 print(n) ;
18 join none
19 }
20 }
21
22 task spawn_process_with_shawdow () {
23 shadow integer n;
24 printf("In spawn_process_with_shadow_variable\n");
25 for(n=0; n<3 ; n++) {
26 fork
27 print(n) ;
28 join none
29 }
30 }
You could download file shadow_variable.vr here
|
|
|
|
|
|
Simulation : shadow variable
|
|
|
|
|
|
In spawn_process
n = 3
n = 3
n = 3
In spawn_process_with_shadow_variable
n = 0
n = 1
n = 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|