debugging, more pthreads crap

This commit is contained in:
rsc 2004-10-22 17:15:30 +00:00
parent 493f3d0fbf
commit ba15d71b0c
7 changed files with 27 additions and 9 deletions

View file

@ -50,6 +50,7 @@ _threadexec(Channel *pidc, int fd[3], char *prog, char *args[], int freeargs)
goto Bad; goto Bad;
case 0: case 0:
efork(fd, pfd, prog, args); efork(fd, pfd, prog, args);
_threaddebug(DBGSCHED, "exit after efork");
_exit(0); _exit(0);
default: default:
_threadafterexec(); _threadafterexec();
@ -152,6 +153,7 @@ efork(int stdfd[3], int fd[2], char *prog, char **args)
strcpy(buf, "exec failed"); strcpy(buf, "exec failed");
write(fd[1], buf, strlen(buf)); write(fd[1], buf, strlen(buf));
close(fd[1]); close(fd[1]);
_threaddebug(DBGSCHED, "_exits in exec-unix");
_exits(buf); _exits(buf);
} }

View file

@ -66,6 +66,7 @@ threadsetname(char *fmt, ...)
t->name = vsmprint(fmt, arg); t->name = vsmprint(fmt, arg);
va_end(arg); va_end(arg);
_threaddebug(DBGSCHED, "set name %s", t->name);
/* Plan 9 only /* Plan 9 only
if(p->nthreads == 1){ if(p->nthreads == 1){
snprint(buf, sizeof buf, "#p/%d/args", getpid()); snprint(buf, sizeof buf, "#p/%d/args", getpid());

View file

@ -50,6 +50,9 @@ tprimes: tprimes.$O $PLAN9/lib/$LIB
texec: texec.$O $PLAN9/lib/$LIB texec: texec.$O $PLAN9/lib/$LIB
$LD -o texec texec.$O $LDFLAGS -lthread -l9 $LD -o texec texec.$O $LDFLAGS -lthread -l9
tspawn: tspawn.$O $PLAN9/lib/$LIB
$LD -o tspawn tspawn.$O $LDFLAGS -lthread -l9
trend: trend.$O $PLAN9/lib/$LIB trend: trend.$O $PLAN9/lib/$LIB
$LD -o trend trend.$O $LDFLAGS -lthread -l9 $LD -o trend trend.$O $LDFLAGS -lthread -l9

View file

@ -87,9 +87,7 @@ _threadnote(void *v, char *s)
Note *n; Note *n;
_threaddebug(DBGNOTE, "Got note %s", s); _threaddebug(DBGNOTE, "Got note %s", s);
if(strncmp(s, "sys:", 4) == 0 if(strncmp(s, "sys:", 4) == 0)
&& strcmp(s, "sys: write on closed pipe") != 0
&& strcmp(s, "sys: child") != 0)
noted(NDFLT); noted(NDFLT);
// if(_threadexitsallstatus){ // if(_threadexitsallstatus){

View file

@ -60,6 +60,7 @@ _threadinitproc(Proc *p)
void void
_threadexitproc(char *exitstr) _threadexitproc(char *exitstr)
{ {
_threaddebug(DBGSCHED, "_pthreadexit");
pthread_exit(nil); pthread_exit(nil);
} }
@ -69,7 +70,8 @@ _threadexitproc(char *exitstr)
void void
_threadexitallproc(char *exitstr) _threadexitallproc(char *exitstr)
{ {
exits(0); _threaddebug(DBGSCHED, "_threadexitallproc");
exits(exitstr);
} }
/* /*
@ -111,6 +113,7 @@ _threadwaitproc(void *v)
else else
free(w); free(w);
} }
fprint(2, "_threadwaitproc exits\n");
} }
/* /*

View file

@ -170,9 +170,10 @@ runthread(Proc *p)
/* /*
* Maybe we were awakened to exit? * Maybe we were awakened to exit?
*/ */
if(_threadexitsallstatus) if(_threadexitsallstatus){
_threaddebug(DBGSCHED, "time to exit");
_exits(_threadexitsallstatus); _exits(_threadexitsallstatus);
}
assert(q->head != nil); assert(q->head != nil);
} }
@ -291,9 +292,12 @@ schedexit(Proc *p)
strncpy(ex, p->exitstr, sizeof ex); strncpy(ex, p->exitstr, sizeof ex);
ex[sizeof ex-1] = '\0'; ex[sizeof ex-1] = '\0';
free(p); free(p);
if(n == 0) if(n == 0){
_threaddebug(DBGSCHED, "procexit; no more procs");
_threadexitallproc(ex); _threadexitallproc(ex);
else }else{
_threaddebug(DBGSCHED, "procexit");
_threadexitproc(ex); _threadexitproc(ex);
}
} }

View file

@ -1,5 +1,12 @@
#include "threadimpl.h" #include "threadimpl.h"
static void
launcher(void (*f)(void*), void *arg)
{
f(arg);
threadexits(nil);
}
void void
_threadinitstack(Thread *t, void (*f)(void*), void *arg) _threadinitstack(Thread *t, void (*f)(void*), void *arg)
{ {
@ -17,7 +24,7 @@ _threadinitstack(Thread *t, void (*f)(void*), void *arg)
/* leave a few words open on both ends */ /* leave a few words open on both ends */
t->context.uc.uc_stack.ss_sp = t->stk+8; t->context.uc.uc_stack.ss_sp = t->stk+8;
t->context.uc.uc_stack.ss_size = t->stksize-16; t->context.uc.uc_stack.ss_size = t->stksize-16;
makecontext(&t->context.uc, (void(*)())f, 1, arg); makecontext(&t->context.uc, (void(*)())launcher, 2, f, arg);
} }
void void