Commit | Line | Data |
---|---|---|
89cfa821 C |
1 | #include <stdio.h> |
2 | ||
3 | extern long random(); | |
4 | ||
5 | int | |
6 | random_flip() | |
7 | { | |
8 | int r = random(); | |
9 | ||
10 | return (r >> 10) & 0x1; | |
11 | } | |
12 | ||
13 | ||
14 | enum color { BLUE, RED}; | |
15 | ||
16 | ||
17 | typedef struct { | |
18 | enum color c; | |
19 | int data[50]; | |
20 | } widgit; | |
21 | ||
22 | ||
23 | widgit | |
24 | *make_widgit() | |
25 | { | |
26 | widgit *w; | |
27 | ||
28 | w = (widgit *) malloc(sizeof(widgit)); | |
29 | return w; | |
30 | } | |
31 | ||
32 | widgit | |
33 | *make_blue_widgit() | |
34 | { | |
35 | widgit *w; | |
36 | ||
37 | w = make_widgit(); | |
38 | w->c = BLUE; | |
39 | return w; | |
40 | } | |
41 | ||
42 | widgit | |
43 | *make_red_widgit() | |
44 | { | |
45 | widgit *w; | |
46 | ||
47 | w = make_widgit(); | |
48 | w->c = RED; | |
49 | return w; | |
50 | } | |
51 | ||
52 | void | |
53 | consume_widgit(w) | |
54 | widgit *w; | |
55 | { | |
56 | if (w->c == BLUE) { | |
57 | /* record blue widgit */ | |
58 | free(w); | |
59 | } else { | |
60 | /* record red widgit */ | |
61 | } | |
62 | } | |
63 | ||
64 | ||
65 | #define NUM_WIDGITS 10000 | |
66 | ||
67 | int | |
68 | main() | |
69 | { | |
70 | int i; | |
71 | widgit *wqueue[NUM_WIDGITS]; | |
72 | /* | |
73 | extern int keeping_leaks; | |
74 | keeping_leaks = 0; | |
75 | */ | |
76 | for (i = 0; i < NUM_WIDGITS; i++) | |
77 | if (random_flip()) | |
78 | wqueue[i] = make_blue_widgit(); | |
79 | else | |
80 | wqueue[i] = make_red_widgit(); | |
81 | ||
82 | for (i = 0; i < NUM_WIDGITS; i++) | |
83 | consume_widgit(wqueue[i]); | |
84 | ||
85 | return 0; | |
86 | } |