Date: Fri, 19 Sep 1997 15:04:29 -0600 (MDT) From: Nate Williams <nate@mt.sri.com> To: Terry Lambert <tlambert@primenet.com> Cc: toor@dyson.iquest.net (John S. Dyson), nate@mt.sri.com, dyson@freebsd.org, karpen@ocean.campus.luth.se, current@freebsd.org Subject: Re: FYI: regarding our rfork(2) Message-ID: <199709192104.PAA20740@rocky.mt.sri.com> In-Reply-To: <199709192027.NAA01303@usr03.primenet.com> References: <199709191848.NAA02645@dyson.iquest.net> <199709192027.NAA01303@usr03.primenet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> The problem is that I may pass auto variables between threads: Then you have problems. > /* one of many threads with work to be done*/ > thread1() > { > struct req my_request; > > my_request.x = ...; > my_request.y = ...; > > do_requeust( &my_request); > > ... > } > > /* block calling thread until request completed*/ > do_request( struct req *preq) > { > ... > enqueue( preq); > ... > while( preq->status != REQ_COMPLETE) > YIELD; > } > > > /* lives only to service requests*/ > thread2() > { > struct req *preq; > > for(;;) { > /* spin to get next work item*/ > while( ( preq = dequeue()) == NULL) > YIELD; > > /* service work item*/ > ... > > /* mark work item completed*/ > preq->status = REQ_COMPLETE; > } > } I would argue that this program has many problems, waiting to happen that could be partially avoided by not using the stack. But, as Sean already pointed out to me many times, "that's the way things work in C, and we need to be backwards compatible". Why not allocate your struct req from the heap, which avoids someone reading/writing bogus data on your stack, thus corrupting it. Then again, I guess you could argue that *IFF* your stack gets corrupted, you'll know you're over-writing memory a heck of a lot quicker. :) In any case, I'm convinced that it's necessary in order to fully support C-Threads. Nate
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709192104.PAA20740>