From: Fco.J.Ballesteros <nemo@plan9.escet.urjc.es>
To: 9fans@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 [thread overview]
Message-ID: <20011120084702.36CA3199E4@mail.cse.psu.edu> (raw)
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;
}
next reply other threads:[~2001-11-20 9:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-20 9:35 Fco.J.Ballesteros [this message]
2001-11-20 14:03 Sape Mullender
2001-11-20 20:51 David Gordon Hogan
2001-11-20 21:15 Sape Mullender
2001-11-21 9:08 Fco.J.Ballesteros
2001-11-21 13:24 rog
2001-11-21 14:34 Fco.J.Ballesteros
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20011120084702.36CA3199E4@mail.cse.psu.edu \
--to=nemo@plan9.escet.urjc.es \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).