From owner-freebsd-current Mon Sep 28 15:25:33 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA09662 for freebsd-current-outgoing; Mon, 28 Sep 1998 15:25:33 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from cimlogic.com.au (cimlog.lnk.telstra.net [139.130.51.31]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA09630 for ; Mon, 28 Sep 1998 15:25:24 -0700 (PDT) (envelope-from jb@cimlogic.com.au) Received: (from jb@localhost) by cimlogic.com.au (8.9.1/8.9.1) id IAA28313; Tue, 29 Sep 1998 08:32:20 +1000 (EST) (envelope-from jb) From: John Birrell Message-Id: <199809282232.IAA28313@cimlogic.com.au> Subject: Re: recvfrom and multiple threads. In-Reply-To: <19980928172212.A307@kublai.com> from Brian Cully at "Sep 28, 98 05:22:12 pm" To: shmit@kublai.com Date: Tue, 29 Sep 1998 08:32:20 +1000 (EST) Cc: current@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL40 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Brian Cully wrote: > I've done a little more poking around with my sigwait problem, and > found another data point. If you'll recall, my program daemonizes, > blocks all signals, opens a socket, spawns off a bunch of worker > threads, and the main thread polls the results of sigwait() for > user events. Daniel Eischen has already responded to your earlier mail about sigwait(). He has submitted patches in a PR that supposedly fix sigwait() without breaking anthing else (this time 8-). I plan to look at that stuff today. > Inside of the worker thread, I call recvfrom() on the socket that > was spawned in the master thread. That's where things break. If I > replace the recvfrom() with a call to sleep() sigwait works just > fine, but with the recvfrom() everything gets hosed. > > Am I wrong in thinking that multiple threads calling recvfrom() on > the same socket should work (ala multiple processes calling recvfrom() > on the same socket)? I suggest you protect calls to recvfrom() by a mutex and condition variable. There is no point having more than one thread wait on a socket doing spinlocks to try and access it. That will just burn CPU. If you use a mutex to protect accesses to the socket and the condition variable to put blocked threads to sleep, your application should work. POSIX threads 101. -- John Birrell - jb@cimlogic.com.au; jb@freebsd.org http://www.cimlogic.com.au/ CIMlogic Pty Ltd, GPO Box 117A, Melbourne Vic 3001, Australia +61 418 353 137 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message