diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-12-21 15:01:12 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-12-22 11:59:46 +0100 |
| commit | 6f298a18e582be006780954d6b0c30cbe2f568f4 (patch) | |
| tree | 4d1da6105aa63eac8d3e233ff62116112fe688d6 /pkg/csource/csource.go | |
| parent | 7b62abdb0abadbaf7b3f3a23ab4d78485fbf9059 (diff) | |
pkg/csource: limit thread stacks
We always set RLIMIT_AS to 128MB. I've debugged a program with 21 syscalls.
With collide it creates 42 threads. With default stack size of 8MB this
requires: 42*8 = 336MB. Thread creation fails and nothing works.
Limit thread stacks the same way executor does.
Fixes #488
Diffstat (limited to 'pkg/csource/csource.go')
| -rw-r--r-- | pkg/csource/csource.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index 9325f5030..1fb00d1c0 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -202,6 +202,7 @@ func (ctx *context) generateTestFunc(calls []string, nvar uint64, name string) { ctx.printf("void %v()\n{\n", name) ctx.printf("\tlong i;\n") ctx.printf("\tpthread_t th[%v];\n", 2*len(calls)) + ctx.printf("\tpthread_attr_t attr;\n") ctx.printf("\n") if opts.Debug { // Use debug to avoid: error: ‘debug’ defined but not used. @@ -216,13 +217,15 @@ func (ctx *context) generateTestFunc(calls []string, nvar uint64, name string) { if opts.Collide { ctx.printf("\tsrand(getpid());\n") } + ctx.printf("\tpthread_attr_init(&attr);\n") + ctx.printf("\tpthread_attr_setstacksize(&attr, 128 << 10);\n") ctx.printf("\tfor (i = 0; i < %v; i++) {\n", len(calls)) - ctx.printf("\t\tpthread_create(&th[i], 0, thr, (void*)i);\n") + ctx.printf("\t\tpthread_create(&th[i], &attr, thr, (void*)i);\n") ctx.printf("\t\tusleep(rand()%%10000);\n") ctx.printf("\t}\n") if opts.Collide { ctx.printf("\tfor (i = 0; i < %v; i++) {\n", len(calls)) - ctx.printf("\t\tpthread_create(&th[%v+i], 0, thr, (void*)i);\n", len(calls)) + ctx.printf("\t\tpthread_create(&th[%v+i], &attr, thr, (void*)i);\n", len(calls)) ctx.printf("\t\tif (rand()%%2)\n") ctx.printf("\t\t\tusleep(rand()%%10000);\n") ctx.printf("\t}\n") |
