| 1 |
(* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. *) |
| 2 |
(* This file is part of GNU Modula-2. |
| 3 |
|
| 4 |
This library is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU Lesser General Public |
| 6 |
License as published by the Free Software Foundation; either |
| 7 |
version 2.1 of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This library is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public |
| 15 |
License along with this library; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *) |
| 17 |
|
| 18 |
MODULE testtransfer ; |
| 19 |
|
| 20 |
FROM SYSTEM IMPORT ADDRESS, PROCESS, NEWPROCESS, TRANSFER ; |
| 21 |
FROM Storage IMPORT ALLOCATE ; |
| 22 |
FROM libc IMPORT printf, exit ; |
| 23 |
|
| 24 |
|
| 25 |
CONST |
| 26 |
MaxStack = 16 * 1024 * 1024 ; |
| 27 |
Debugging = FALSE ; |
| 28 |
MaxCount = 1000 ; |
| 29 |
|
| 30 |
|
| 31 |
PROCEDURE p1 ; |
| 32 |
BEGIN |
| 33 |
LOOP |
| 34 |
IF Debugging |
| 35 |
THEN |
| 36 |
printf('hello world process 1\n') |
| 37 |
END ; |
| 38 |
TRANSFER(P1, P2) ; |
| 39 |
IF Debugging |
| 40 |
THEN |
| 41 |
printf('after TRANSFER in process 2\n') |
| 42 |
END |
| 43 |
END |
| 44 |
END p1 ; |
| 45 |
|
| 46 |
|
| 47 |
PROCEDURE p2 ; |
| 48 |
BEGIN |
| 49 |
LOOP |
| 50 |
IF Debugging |
| 51 |
THEN |
| 52 |
printf('hello world process 2 (%d)\n', count) |
| 53 |
END ; |
| 54 |
TRANSFER(P2, P1) ; |
| 55 |
IF Debugging |
| 56 |
THEN |
| 57 |
printf('after TRANSFER in process 2\n') |
| 58 |
END ; |
| 59 |
INC(count) ; |
| 60 |
IF count=MaxCount |
| 61 |
THEN |
| 62 |
printf('completed %d TRANSFERs successfully\n', count) ; |
| 63 |
exit(0) |
| 64 |
END |
| 65 |
END |
| 66 |
END p2 ; |
| 67 |
|
| 68 |
|
| 69 |
VAR |
| 70 |
MainP, P1, P2: PROCESS ; |
| 71 |
S1, S2, S3 : ADDRESS ; |
| 72 |
count : CARDINAL ; |
| 73 |
BEGIN |
| 74 |
printf ("inside testtransfer\n"); |
| 75 |
count := 0 ; |
| 76 |
ALLOCATE(S1, MaxStack) ; |
| 77 |
ALLOCATE(S2, MaxStack) ; |
| 78 |
ALLOCATE(S3, MaxStack) ; |
| 79 |
printf ("before newprocess 1\n"); |
| 80 |
NEWPROCESS(p1, S1, MaxStack, P1) ; |
| 81 |
printf ("before newprocess 2\n"); |
| 82 |
NEWPROCESS(p2, S2, MaxStack, P2) ; |
| 83 |
printf ("before TRANSFER\n"); |
| 84 |
TRANSFER(MainP, P1) ; |
| 85 |
printf ("program finishing - which should not occur here!\n"); |
| 86 |
exit (1) |
| 87 |
END testtransfer. |