quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Introduction

Vera supports features to help model parallel, independent activities. We will be covering following features of Vera language.

   

space.gif

  • fork - join
  • wait_var()
  • event methods
  • semaphores
  • region
  • mailboxes
  • timeouts
   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif

Syntax : fork-join

   

space.gif

fork
{
  statement1;
}
{
  statement2;
}
  ...
{
  statementN;
}
join [all | any | none]
   

space.gif

Below Table shows the details of all join

   

space.gif

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.

   

space.gif

  ../images/main/bullet_star_pink.gif Example : fork join
   

space.gif


  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
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : fork join
   

space.gif

 ----------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
   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif

  • 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.
   

space.gif

  ../images/main/bullet_star_pink.gif Example : shadow variable
   

space.gif


  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
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : shadow variable
   

space.gif

 In spawn_process
    n = 3
    n = 3
    n = 3
 In spawn_process_with_shadow_variable
    n = 0
    n = 1
    n = 2
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com