From owner-freebsd-hackers Thu Apr 15 10:48:46 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from labinfo.iet.unipi.it (labinfo.iet.unipi.it [131.114.9.5]) by hub.freebsd.org (Postfix) with SMTP id 25C721506D for ; Thu, 15 Apr 1999 10:48:42 -0700 (PDT) (envelope-from luigi@labinfo.iet.unipi.it) Received: from localhost (luigi@localhost) by labinfo.iet.unipi.it (8.6.5/8.6.5) id RAA13015; Thu, 15 Apr 1999 17:30:11 +0200 From: Luigi Rizzo Message-Id: <199904151530.RAA13015@labinfo.iet.unipi.it> Subject: Re: Programming Resources To: cracauer@cons.org (Martin Cracauer) Date: Thu, 15 Apr 1999 17:30:10 +0200 (MET DST) Cc: avalon@advicom.net, freebsd-hackers@FreeBSD.ORG In-Reply-To: <19990415193106.A6631@cons.org> from "Martin Cracauer" at Apr 15, 99 07:30:47 pm X-Mailer: ELM [version 2.4 PL23] Content-Type: text Content-Length: 1594 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > Does anyone have any useful links/ftp sites/books (etc.) for those of us > > new to multi-threaded programming (for daemons, etc.)? Obviously, ... > If you aren't already set for threading, you should also consider the > classic fork()/pipe()-based concurrency scheme of UNIX > systems. Steven's "Advanced Programming in the UNIX Environment" is > the cannonical best choice here. I generally prefer it over threads > for various reasons and most daemons on FreeBSD use it as well. as another alternative to threads, in many cases i also tend to use a single process looping around a select(), and structure the handling of each socket as a state machine, doing non-blocking actions at once and returning to the select when a blocking calls is about to be made. For some types of servers (e.g. www, multi-user talk daemons, etc.) this works quite nicely because most of times there is little processing involved between I/O calls, and restructuring the code in a way that can be put into the main loop almost only requires to replace read() and write()'s with things like state = THE_NEW_STATE ; break ; case THE_NEW_STATE : (if you know what you do, that is...) cheers luigi -----------------------------------+------------------------------------- Luigi RIZZO . EMAIL: luigi@iet.unipi.it . Dip. di Ing. dell'Informazione HTTP://www.iet.unipi.it/~luigi/ . Universita` di Pisa TEL/FAX: +39-050-568.533/522 . via Diotisalvi 2, 56126 PISA (Italy) -----------------------------------+------------------------------------- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message