| 30 | } |
| 31 | |
| 32 | int main(int argc, char* argv[]) |
| 33 | { |
| 34 | int max = 50000000, ch; |
| 35 | acl::string type("tbox"); |
| 36 | acl::box<int>* box; |
| 37 | |
| 38 | while ((ch = getopt(argc, argv, "ht:n:")) > 0) { |
| 39 | switch (ch) { |
| 40 | case 'h': |
| 41 | usage(argv[0]); |
| 42 | return 0; |
| 43 | case 't': |
| 44 | type = optarg; |
| 45 | break; |
| 46 | case 'n': |
| 47 | max = atoi(optarg); |
| 48 | break; |
| 49 | default: |
| 50 | break; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (type == "tbox") { |
| 55 | box = new acl::tbox<int>; |
| 56 | } else if (type == "tbox_array") { |
| 57 | box = new acl::tbox_array<int>; |
| 58 | } else if (type == "mbox") { |
| 59 | box = new acl::mbox<int>; |
| 60 | } else { |
| 61 | printf("unknown type=%s\r\n", type.c_str()); |
| 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | producer thr(*box, max); |
| 66 | thr.start(); |
| 67 | |
| 68 | for (int i = 0; i < max; i++) { |
| 69 | int* n = box->pop(); |
| 70 | assert(*n == i); |
| 71 | delete n; |
| 72 | } |
| 73 | |
| 74 | printf("All over, box type=%s, max=%d\r\n", type.c_str(), max); |
| 75 | thr.wait(); |
| 76 | |
| 77 | delete box; |
| 78 | return 0; |
| 79 | } |