diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-08-28 16:37:24 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-08-28 16:37:24 +0200 |
| commit | 1f9bd1e845b86c5cff81c8593fefc4a9e0568bd0 (patch) | |
| tree | 645b484d0acc2614143970b5e91bdc9821572dea /csource | |
| parent | 8278953eb4abb4fb147f6f06cd9bdcf1eff7e84d (diff) | |
csource: make collide mode more random
Update #59
Diffstat (limited to 'csource')
| -rw-r--r-- | csource/csource.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/csource/csource.go b/csource/csource.go index 28be9e22a..9bd349b7c 100644 --- a/csource/csource.go +++ b/csource/csource.go @@ -75,19 +75,20 @@ int main() fmt.Fprintf(w, "int main()\n{\n") fmt.Fprintf(w, "\tlong i;\n") - fmt.Fprintf(w, "\tpthread_t th[%v];\n", len(calls)) + fmt.Fprintf(w, "\tpthread_t th[%v];\n", 2*len(calls)) fmt.Fprintf(w, "\n") fmt.Fprintf(w, "install_segv_handler();\n") fmt.Fprintf(w, "\tmemset(r, -1, sizeof(r));\n") + fmt.Fprintf(w, "\tsrand(getpid());\n") fmt.Fprintf(w, "\tfor (i = 0; i < %v; i++) {\n", len(calls)) fmt.Fprintf(w, "\t\tpthread_create(&th[i], 0, thr, (void*)i);\n") fmt.Fprintf(w, "\t\tusleep(10000);\n") fmt.Fprintf(w, "\t}\n") if opts.Collide { fmt.Fprintf(w, "\tfor (i = 0; i < %v; i++) {\n", len(calls)) - fmt.Fprintf(w, "\t\tpthread_create(&th[i], 0, thr, (void*)i);\n") - fmt.Fprintf(w, "\t\tif (i%%2==0)\n") - fmt.Fprintf(w, "\t\t\tusleep(10000);\n") + fmt.Fprintf(w, "\t\tpthread_create(&th[%v+i], 0, thr, (void*)i);\n", len(calls)) + fmt.Fprintf(w, "\t\tif (rand()%%2)\n") + fmt.Fprintf(w, "\t\t\tusleep(rand()%%10000);\n") fmt.Fprintf(w, "\t}\n") } fmt.Fprintf(w, "\tusleep(100000);\n") |
