Date: Mon, 01 Nov 1999 15:17:42 -0800 From: Jake Burkholder <jake@checker.org> To: Peter Dufault <dufault@hda.com> Cc: freebsd-arch@freebsd.org Subject: Re: Threads goals version III Message-ID: <19991101231743.F30501FD7@io.yi.org> In-Reply-To: Your message of "Mon, 01 Nov 1999 16:53:10 EST." <199911012153.QAA19185@hda.hda.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> Obviously he can't return though. Here's what I would > argue for in setting a standards document: > > main() > { > int mainvar; > > newthread(t1); /* t1 is a thread and it can access mainvar... */ > > sub(); > } > > sub() > { > int subvar; > > newthread(t2); /* t2 can access subvar or mainvar, but maybe > * t1 can't access subvar. > * Maybe the stack just crossed a page boundary. > */ > > while(1) > keep_stack_context(); > } > I think there's confusion here, forking a new thread is not like forking a new process. A start routine needs to be passed in and a new stack and context setup, so the thread begins execution as if start_routine were its "main". See Daniel's {get,set,make,swap}context diffs. I supposed that newthread(t1) could mean that there is now a new thread, which starts executing at the point newthread was called (in main), only on a new stack, but that doesn't seem to me to be the way it is commonly implemented. int global; /* all threads can access this */ main() { thread t1; int mainvar; /* this could also be mmaped or stack based storage */ t.stack = malloc(some memory); new_thread(&t1, foo, 1, &mainvar); sub(); wait(t1); } sub() { thread t2; int subvar; /* t1 has no access to this at all */ new_thread(&t2, foo, 1, &subvar); wait(t2); } foo(int ac, ...) { int *p; va_list ap; assert(ac == 1); va_start(ap, ac); p = va_arg(ap, int *) va_end(ap); /* t1 now has access to mainvar through p */ /* t2 now has access to subvar through p */ } The WHOLE address space is shared. You can pass around pointers to stack based storage, but a new thread executes a new start_routine, so it can't access variables from the scope in which new_thread was called, only what get passed into start_routine. At least that is my understanding. Apologies if I misinterpreted what you were trying to say. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991101231743.F30501FD7>