4 #include "threadimpl.h"
6 typedef struct Mainarg Mainarg;
16 static jmp_buf _mainjmp;
17 static void mainlauncher(void*);
18 extern void (*_sysfatal)(char*, va_list);
19 extern void (*__assert)(char*);
24 main(int argc, char **argv)
34 //_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;
36 _qlockinit(_threadrendezvous);
37 _sysfatal = _threadsysfatal;
38 __assert = _threadassert;
40 if(mainstacksize == 0)
41 mainstacksize = 8*1024;
43 a = _threadmalloc(sizeof *a, 1);
47 p = _newproc(mainlauncher, a, mainstacksize, "threadmain", 0, 0);
49 abort(); /* not reached */
53 mainlauncher(void *arg)
58 threadmain(a->argc, a->argv);
59 threadexits("threadmain");
67 while(*p != ' ' && *p != 0)
77 _threaddebug(DBGEXEC, "_schedexec %s", e->prog);
79 exec(e->prog, e->args);
80 _threaddebug(DBGEXEC, "_schedexec failed: %r");
81 rerrstr(buf, sizeof buf);
83 strcpy(buf, "exec failed");
84 write(e->fd[1], buf, strlen(buf));
89 _schedexec(Execargs *e)
93 flag = (_threadwaitchan == nil) ? RFNOWAIT : 0;
94 switch(pid = rfork(RFREND|RFNOTEG|RFFDG|RFMEM|RFPROC|flag)){
107 switch(pid = rfork(RFPROC|RFMEM|RFNOWAIT|p->rforkflag)){
109 *mainp = p; /* write to stack, so local to proc */
110 longjmp(_mainjmp, 1);
122 lock(&_threadpq.lock);
123 for(l=&_threadpq.head; *l; l=&(*l)->next){
131 unlock(&_threadpq.lock);
133 utfecpy(ex, ex+sizeof ex, p->exitstr);
147 p = _threadgetproc();
150 _threaddebug(DBGEXEC, "_schedexecwait %d", t->ret);
162 if((c = _threadwaitchan) != nil)
167 threadexits("procexec");
185 _threadsetproc(Proc *p)