| 1 | extern void __VERIFIER_error();
|
|---|
| 2 |
|
|---|
| 3 | #include <stdio.h>
|
|---|
| 4 | #include <stdlib.h>
|
|---|
| 5 | #include <pthread.h>
|
|---|
| 6 |
|
|---|
| 7 | #define USAGE "./reorder <param1> <param2>\n"
|
|---|
| 8 |
|
|---|
| 9 | static int iSet = 2;
|
|---|
| 10 | static int iCheck = 2;
|
|---|
| 11 |
|
|---|
| 12 | static int a = 0;
|
|---|
| 13 | static int b = 0;
|
|---|
| 14 |
|
|---|
| 15 | void *setThread(void *param);
|
|---|
| 16 | void *checkThread(void *param);
|
|---|
| 17 | void set();
|
|---|
| 18 | int check();
|
|---|
| 19 |
|
|---|
| 20 | int main(int argc, char *argv[]) {
|
|---|
| 21 | int i, err;
|
|---|
| 22 |
|
|---|
| 23 | if (argc != 1) {
|
|---|
| 24 | if (argc != 3) {
|
|---|
| 25 | fprintf(stderr, USAGE);
|
|---|
| 26 | exit(-1);
|
|---|
| 27 | } else {
|
|---|
| 28 | sscanf(argv[1], "%d", &iSet);
|
|---|
| 29 | sscanf(argv[2], "%d", &iCheck);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | //printf("iSet = %d\niCheck = %d\n", iSet, iCheck);
|
|---|
| 34 |
|
|---|
| 35 | pthread_t setPool[iSet];
|
|---|
| 36 | pthread_t checkPool[iCheck];
|
|---|
| 37 |
|
|---|
| 38 | for (i = 0; i < iSet; i++) {
|
|---|
| 39 | if (0 != (err = pthread_create(&setPool[i], NULL, &setThread, NULL))) {
|
|---|
| 40 | fprintf(stderr, "Error [%d] found creating set thread.\n", err);
|
|---|
| 41 | exit(-1);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | for (i = 0; i < iCheck; i++) {
|
|---|
| 46 | if (0 != (err = pthread_create(&checkPool[i], NULL, &checkThread,
|
|---|
| 47 | NULL))) {
|
|---|
| 48 | fprintf(stderr, "Error [%d] found creating check thread.\n", err);
|
|---|
| 49 | exit(-1);
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | for (i = 0; i < iSet; i++) {
|
|---|
| 54 | if (0 != (err = pthread_join(setPool[i], NULL))) {
|
|---|
| 55 | fprintf(stderr, "pthread join error: %d\n", err);
|
|---|
| 56 | exit(-1);
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | for (i = 0; i < iCheck; i++) {
|
|---|
| 61 | if (0 != (err = pthread_join(checkPool[i], NULL))) {
|
|---|
| 62 | fprintf(stderr, "pthread join error: %d\n", err);
|
|---|
| 63 | exit(-1);
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | return 0;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void *setThread(void *param) {
|
|---|
| 71 | a = 1;
|
|---|
| 72 | b = -1;
|
|---|
| 73 |
|
|---|
| 74 | return NULL;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void *checkThread(void *param) {
|
|---|
| 78 | if (! ((a == 0 && b == 0) || (a == 1 && b == -1))) {
|
|---|
| 79 | fprintf(stderr, "Bug found!\n");
|
|---|
| 80 | ERROR: __VERIFIER_error();
|
|---|
| 81 | goto ERROR;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | return NULL;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|