Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Fri, 24 Jan 2003 18:30:03 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Fri, 24 Jan 2003 18:30:03 -0500 Received: from air-2.osdl.org ([65.172.181.6]:27373 "EHLO mail.osdl.org") by vger.kernel.org with ESMTP id ; Fri, 24 Jan 2003 18:30:02 -0500 Date: Fri, 24 Jan 2003 15:29:40 -0800 (PST) From: "Randy.Dunlap" X-X-Sender: To: Matti Aarnio cc: Corey Minyard , Mark Mielke , Dan Kegel , Mark Hahn , Subject: Re: debate on 700 threads vs asynchronous code In-Reply-To: <20030124232110.GN787@mea-ext.zmailer.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 25 Jan 2003, Matti Aarnio wrote: | On Fri, Jan 24, 2003 at 04:53:46PM -0600, Corey Minyard wrote: | ... | > I would disagree. One thread per connection is easier to conceptually | > understand. In my experience, an event-driven model (which is what you | > end up with if you use one or a few threads) is actually easier to | > correctly implement and it tends to make your code more modular and | > portable. | | An old thing from early annals of computer science (I browsed Knuth's | "The Art" again..) is called Coroutine. | | Gives you "one thread per connection" programming model, but without | actual multiple scheduling threads in the kernel side. | | Simplest coroutine implementations are truly simple.. Pagefull of C. | Knuth shows it with very few MIX (assembly) instructions. | | Throwing in non-blocking socket/filedescriptor access, and in event | of "EAGAIN", coroutine-yielding to some other coroutine, does complicate | things, naturally. | | Good coder finds balance in between various methods, possibly uses | both coroutine "userspace threads", and actual kernel threads. | | Doing coroutine library all in portable C (by means of setjmp()/longjmp()) | is possible, but not very efficient. A bit of assembly helps a lot. | | > -Corey | | /Matti Aarnio | - Davide Libenzi (epoll) likes and discusses coroutines on one of his web pages: http://www.xmailserver.org/linux-patches/nio-improve.html (search for /coroutine/) -- ~Randy - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/