From owner-freebsd-hackers Fri Nov 26 12:35:58 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from spirit.jaded.net (spirit.jaded.net [216.94.113.12]) by hub.freebsd.org (Postfix) with ESMTP id E9CB91529E for ; Fri, 26 Nov 1999 12:35:12 -0800 (PST) (envelope-from dan@spirit.jaded.net) Received: (from dan@localhost) by spirit.jaded.net (8.9.3/8.9.3) id PAA02374; Fri, 26 Nov 1999 15:36:49 -0500 (EST) Date: Fri, 26 Nov 1999 15:36:49 -0500 From: Dan Moschuk To: Rob King Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: PThreads and Sockets Message-ID: <19991126153649.A1358@spirit.jaded.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from dimwit@pernet.net on Fri, Nov 26, 1999 at 01:20:52PM -0600 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG | Hi all, | I'm writing a server that multiplexes a MySQL connection to several | clients. Since the connection has to be shared, I can't fork(), I have to | thread. This isn't a problem, except that when I accept() and assign a | socket descriptor, the first thread runs fine, but the next thread simply | grabs the descriptor (since it's shared) from the previous thread and | starts doing all its writing to that socket. Any idea how to get around | this? If there's any good example code, please let me know. | | Thanks, | Rob Err, how exactly is your server model setup? Do you create a thread after the accept call to handle the connection, or do you pre-spawn threads in a pool? If you allocate the socket descriptor for the client in the starting routine for the thread, it should have its own copy. -- Dan Moschuk (TFreak!dan@freebsd.org) "Cure for global warming: One giant heatsink and dual fans!" To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message