From owner-freebsd-arch Mon Nov 1 15:18:53 1999 Delivered-To: freebsd-arch@freebsd.org Received: from ns1.yes.no (ns1.yes.no [195.204.136.10]) by hub.freebsd.org (Postfix) with ESMTP id D407014E01 for ; Mon, 1 Nov 1999 15:18:48 -0800 (PST) (envelope-from eivind@bitbox.follo.net) Received: from bitbox.follo.net (bitbox.follo.net [195.204.143.218]) by ns1.yes.no (8.9.3/8.9.3) with ESMTP id AAA09673 for ; Tue, 2 Nov 1999 00:18:47 +0100 (CET) Received: (from eivind@localhost) by bitbox.follo.net (8.8.8/8.8.6) id AAA76489 for freebsd-arch@freebsd.org; Tue, 2 Nov 1999 00:18:46 +0100 (MET) Received: from io.yi.org (24.66.174.118.bc.wave.home.com [24.66.174.118]) by hub.freebsd.org (Postfix) with ESMTP id CC69A156A8 for ; Mon, 1 Nov 1999 15:17:36 -0800 (PST) (envelope-from jake@checker.org) Received: from io.yi.org (localhost [127.0.0.1]) by io.yi.org (Postfix) with ESMTP id F30501FD7; Mon, 1 Nov 1999 15:17:42 -0800 (PST) X-Mailer: exmh version 2.1.0 09/18/1999 To: Peter Dufault Cc: freebsd-arch@freebsd.org Subject: Re: Threads goals version III In-reply-to: Your message of "Mon, 01 Nov 1999 16:53:10 EST." <199911012153.QAA19185@hda.hda.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 01 Nov 1999 15:17:42 -0800 From: Jake Burkholder Message-Id: <19991101231743.F30501FD7@io.yi.org> Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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