Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Sep 1998 17:33:44 -0400 (EDT)
From:      Daniel Eischen <eischen@vigrid.com>
To:        current@FreeBSD.ORG, shmit@kublai.com
Subject:   Re: Pthreads, signals, fork, and me.
Message-ID:  <199809252133.RAA05133@pcnet1.pcnet.com>

next in thread | raw e-mail | index | archive | help
> I've a strange problem I'm having with some threading code I'm
> writing on my FreeBSD box. Basically, I have a process that goes
> daemonic, blocks all signals, spawns a bunch of threads, and then
> the main thread hangs out polling the results of sigwait() for
> something interesting.

Sigwait is broken.  I submitted a patch to fix it, but it hasn't
been applied (nor tested by anyone else but me, AFAIK).  The way
the pthreads code exists now, threads suspended on sigsuspend and
sigwait are placed in the same state which isn't correct.  The signal
masks mean entirely different things.  I believe the patch I submitted
fixes this.  See kern/7586.  The patch also includes a test program
to verify sigwait.  Perhaps it will be helpful.

> The problem is that I never see anything interesting, I cannot,
> for the life of me figure out how to get sigwait() to ever return.
> It just sleeps.

That is what I observed also.

> The interesting thing is that if I don't become a daemon, sigwait()
> does the right thing.

It looks like a thread suspended on sigwait will only unblock if
there is a signal handler installed for the occurring signal (even
if it's not in the sigwait mask).  When are your signal handlers
installed, before or after the fork, and from which process?

> Has any one heard of symptoms like that?
> 
> Also, I have a couple of questions that aren't answered by the ORA
> Pthreads book:
>         * Can I use sigprocmask() instead of pthread_signal()? It
>           appears that you can with FreeBSD, but I don't know if
>           it's  POSIX.
>         * Are signal handlers supposed to get called even if you
>           are doing a sigwait() for that particular signal?

No.  A thread suspended on sigwait waits indefinitely until a signal
occurs that is in the signal mask (specified in the call to sigwait).
The signal handler should not get called.

> Suffice it to say, I'm fairly new to this pthreads thing (though
> not threading in general), and the ORA book leaves a lot to be
> desired. Is there another book I can grab that explains pthreads
> any better? An URL?

Actually, I found the Solaris man pages to be quite useful, especially
with regard to signals.

Dan Eischen
eischen@vigrid.com

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?199809252133.RAA05133>