From 6f298a18e582be006780954d6b0c30cbe2f568f4 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 21 Dec 2017 15:01:12 +0100 Subject: 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 --- pkg/csource/csource.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'pkg/csource/csource.go') 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") -- cgit mrf-deployment