From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,2aedba6752dd2388 X-Google-Attributes: gidf678f,public X-Google-ArrivalTime: 1993-10-16 10:19:07 PST Newsgroups: comp.unix.osf.misc Path: gmd.de!xlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!cs.utexas.edu!TAMUTS.TAMU.EDU!news.utdallas.edu!corpgate!nrtpa038!brtph560!brtph316!chrisf From: chrisf@brtph316.bnr.ca (Chris Fulmer) Subject: Re: Threads better than forks? Message-ID: <1993Oct15.173932.9580@brtph560.bnr.ca> Sender: chrisf@brtph316 (Chris Fulmer) Reply-To: woodstock!chris@mcnc.org Organization: BNR Dept 3B91, RTP References: Date: Fri, 15 Oct 1993 17:39:32 GMT In article , swh@aaahq05.aaa.com (Steven Wayne Hudson) writes: > Also, what is the functional (NOT operational) difference between a thread > and fork? Theoretically, I don't think that there's a computational difference between the two -- ie for everything that you can do in one style, you can theoretically do in the other. But, the code may look a lot different. With threads, for instance, you could write a server which had a thread for each client, and those threads were responsible for verifying client input, etc.... And, you could have another server thread for actually handling client requests. The threads directly servicing the clients could pass the file descriptor of the client to the "main" thread, which then sent a reply message back to the client on the FD that was passed in. If you did that with heavy-weight processes, the main guy would have to send the message back to the service threads, which then forwarded it back to the client. Functionally the same, but harder to program. (Note that I'm not saying that this is the way that you'd want to write a server process...) The advantage of threading is that everything is implicitly shared. If your version of unix supports shared memory, you can do the same things yourself, but you have to set them up. (You also couldn't share any of the per-process things, like file descriptors or whatever...) Because of the communication problem, when writing servers, people rarely write ones which fork() for each new client. Instead, they'll keep some context information on them, and do the switching between contexts themselves. This is especially true if there are inter-client dependancies. With threads, it's easy -- just fork off a new thread. If you need some information, it's stored someplace global to all the threads. ------------------------------------------------------ Chris Fulmer Bell-Northern Research Sr. Software Designer Research Triangle, NC mail to woodstock!chris@mcnc.org (preferable) or... chrisf@bnr.ca (not so preferable) Oh yeah. The usual disclaimers apply here.