|
|
|
|
|
|
|
|
|
|
|
|
terminate and return
|
|
|
A return statement causes a task to return immediately to its caller. A return statement causes the task to return to its caller immediately. If the execution of a task falls through to its end, an implicit return is executed. What return does not do is terminate all the child threads. |
|
|
|
|
|
The terminate statement terminates all descendants of the process in which it was called. What terminate does is, it terminate all the child threads. |
|
|
|
|
|
|
|
|
|
|
|
Example : return and terminate
|
|
|
|
|
|
1 #include "vera_defines.vrh"
2
3 program task_terminate {
4 task t1 () {
5 printf("%0d Inside t1\n", get_time(LO));
6 fork
7 { t2(); }
8 { t3(); }
9 join none
10 delay(100);
11 printf("%0d terminating t1 child process\n", get_time(LO));
12 terminate;
13 printf("%0d afterterminate in t1\n", get_time(LO));
14
15 }
16
17 task t2 () {
18 printf("%0d Inside t2\n", get_time(LO));
19 fork
20 { t2_t1(); }
21 join none
22 delay(40);
23 printf("%0d Returning from t2\n", get_time(LO));
24 return;
25 }
26
27 task t3 () {
28 while (1) {
29 delay(5);
30 printf("%0d from t2_t1_t1\n", get_time(LO));
31 }
32 }
33
34 task t2_t1 () {
35 printf("%0d Inside t2_t1\n", get_time(LO));
36 fork
37 { t2_t1_t1(); }
38 join none
39 }
40
41 task t2_t1_t1 () {
42 while (1) {
43 delay(4);
44 printf("%0d from t2_t1_t1\n", get_time(LO));
45 }
46 }
47
48 t1();
49 delay(100);
50 printf("%0d terminating program\n", get_time(LO));
51
52 }
You could download file task_terminate.vr here
|
|
|
|
|
|
Simulation : return and terminat
|
|
|
|
|
|
0 Inside t1
0 Inside t2
0 Inside t2_t1
4 from t2_t1_t1
5 from t2_t1_t1
8 from t2_t1_t1
10 from t2_t1_t1
12 from t2_t1_t1
15 from t2_t1_t1
16 from t2_t1_t1
20 from t2_t1_t1
20 from t2_t1_t1
24 from t2_t1_t1
25 from t2_t1_t1
28 from t2_t1_t1
30 from t2_t1_t1
32 from t2_t1_t1
35 from t2_t1_t1
36 from t2_t1_t1
40 Returning from t2
40 from t2_t1_t1
40 from t2_t1_t1
44 from t2_t1_t1
45 from t2_t1_t1
48 from t2_t1_t1
50 from t2_t1_t1
52 from t2_t1_t1
55 from t2_t1_t1
56 from t2_t1_t1
60 from t2_t1_t1
60 from t2_t1_t1
64 from t2_t1_t1
65 from t2_t1_t1
68 from t2_t1_t1
70 from t2_t1_t1
72 from t2_t1_t1
75 from t2_t1_t1
76 from t2_t1_t1
80 from t2_t1_t1
80 from t2_t1_t1
84 from t2_t1_t1
85 from t2_t1_t1
88 from t2_t1_t1
90 from t2_t1_t1
92 from t2_t1_t1
95 from t2_t1_t1
96 from t2_t1_t1
100 terminating t1
200 terminating program
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|