Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Sep 1998 08:32:20 +1000 (EST)
From:      John Birrell  <jb@cimlogic.com.au>
To:        shmit@kublai.com
Cc:        current@FreeBSD.ORG
Subject:   Re: recvfrom and multiple threads.
Message-ID:  <199809282232.IAA28313@cimlogic.com.au>
In-Reply-To: <19980928172212.A307@kublai.com> from Brian Cully at "Sep 28, 98 05:22:12 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809282232.IAA28313>