source: CIVL/examples/pthread/trans1.cvl@ 4b4bbb3

1.23 2.0 main test-branch
Last change on this file since 4b4bbb3 was 38374b7, checked in by John Edenhofner <johneden@…>, 12 years ago

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@984 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/********************************************************
2 * An example source module to accompany...
3 *
4 * "Using POSIX Threads: Programming with Pthreads"
5 * by Brad nichols, Dick Buttlar, Jackie Farrell
6 * O'Reilly & Associates, Inc.
7 *
8 ********************************************************
9 * simple_threads.c
10 *
11 * Simple multi-threaded example.
12 */
13
14#include <civlc.h>
15#include <stdio.h>
16
17$input int INUM;
18$input int JNUM;
19$input int IBOUND;
20$input int JBOUND;
21
22$assume 0 < INUM && INUM <= IBOUND;
23$assume 0 < JNUM && JNUM <= JBOUND;
24
25int r1 = 0;
26int r2 = 0;
27
28void do_one_thing(int *pnum_times)
29{
30 int i, j;
31 int x = 0;
32
33 for (i = 0; i < INUM; i++) {
34 printf("doing one thing\n");
35 for (j = 0; j < JNUM; j++){
36 x = x + i;
37 (*pnum_times)++;
38 }
39 }
40}
41
42void do_another_thing(int *pnum_times)
43{
44 int i, j;
45 int x = 0;
46
47 for (i = 0; i < INUM; i++) {
48 printf("doing another \n");
49 for (j = 0; j < JNUM; j++){
50 x = x + i;
51 (*pnum_times)++;
52 }
53 }
54}
55
56void do_wrap_up(int one_times, int another_times)
57{
58 int total;
59
60 total = one_times + another_times;
61 printf("All done, one thing %d, another %d for a total of %d\n",
62 one_times, another_times, total);
63}
64
65void main()
66{
67 $proc thread1, thread2;
68
69 thread1 = $spawn do_one_thing(&r1);
70 thread2 = $spawn do_another_thing(&r2);
71
72 $wait thread1;
73 $wait thread2;
74
75 do_wrap_up(r1, r2);
76
77 $assert (r1==INUM*JNUM);
78 $assert (r2==INUM*JNUM);
79}
80
81
Note: See TracBrowser for help on using the repository browser.