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