From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: Fco.J.Ballesteros MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Message-Id: <20011120084702.36CA3199E4@mail.cse.psu.edu> Subject: [9fans] silent limit in thread(2) Channels which can corrupt the stack? Date: Tue, 20 Nov 2001 10:35:13 +0100 Topicbox-Message-UUID: 25330cbe-eaca-11e9-9e20-41e7f4b1d025 Hi, while debugging a program which uses thread(2), I've come to a point where an apparently correct program causes stack corruption on one of the threads. Tracking down the problem, I've found that the program I show below seems to exceed a silent limit in the implementation of channels. I think that if enough pressure is put on a channel it can corrupt your stack without a warning. Please, correct me if I'm wrong, I'd be happy to get any info regarding what's going on. The point where I think the channel has problems is (libthread/channel.c): // enqueue on the channel for (i = 0; i < 32; i++) if ((c->qused & (1 << i)) == 0) { c->qentry[i] = &a; c->qused |= a.q = 1 << i; break; } In case I'm right, I'd suggest calling abort() when the limit is exceeded. This is the stack I get: acid: At pc:0x00002eb2:sleep+0x7 /sys/src/libc/9syscall/sleep.s:5 sleep() /sys/src/libc/9syscall/sleep.s:3 called from main+0x197 /sys/src/libthread/thread.c:500 main(argc=0x00000001,argv=0x7fffefec) /sys/src/libthread/thread.c:459 called from _main+0x31 /sys/src/libc/386/main9.s:16 acid: and this is smallest the program I got that presents the problem: Channel c; int t; void s(void *p) { for(;;){ if (t) break; recv(&c, nil); } } void r(void *p) { int i = 1; for(;;){ send(&c, &i); if (t) break; } } void threadmain() { int i; chaninit(&c, sizeof(int), 0); for (i = 0; i < 50; i++) proccreate(r, (void*)i, 16*1024); for (i = 0; i < 50; i++) proccreate(s, (void*)i, 16*1024); sleep(5*1000); t = 1; }