From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: process doesn't terminate when closing streams from another thread
Date: Mon, 7 Sep 2015 00:50:44 -0400 [thread overview]
Message-ID: <20150907045044.GY17773@brightrain.aerifal.cx> (raw)
In-Reply-To: <20150906170033.GL28959@port70.net>
On Sun, Sep 06, 2015 at 07:00:33PM +0200, Szabolcs Nagy wrote:
> * Nuno Gon?alves <nunojpg@gmail.com> [2015-09-06 15:44:45 +0100]:
> > I'm having problems when closing streams from another thread.
> >
> > The following code:
> >
> > static void *func(void *arg)
> > {
> > fclose(stdout);
> > fprintf(stderr,"Thread about to exit\n");
> > return 0;
> > }
> >
> > int main(int argc, char **argv)
> > {
> > int thread_id;
>
> s/int/pthread_t/
>
> > pthread_create(&thread_id,NULL,&func,NULL);
> > pthread_join(thread_id,NULL);
> > fprintf(stderr,"Process about to terminate\n");
> > return 0;
> > }
> >
> > Prints:
> >
> > root@OpenWrt:/tmp# ./myapp_withmusl
> > Thread about to exit
> > Process about to terminate
> >
> > But never returns! I have to send it a SIGINT.
> >
>
> yes, musl fflushes stdout on fflush(0) even if
> it is closed. (fflush(0) is called at exit,
> fflushing a closed stream is undefined behaviour).
>
> this might be a musl bug.
Yes, this is indeed a musl bug. Getting the right fix is non-trivial
but I think it will involve having fclose unlock the FILE but ensure
that its contents are setup such that the exit-time code behaves as a
no-op.
Rich
next prev parent reply other threads:[~2015-09-07 4:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-06 14:44 Nuno Gonçalves
2015-09-06 17:00 ` Szabolcs Nagy
2015-09-07 4:50 ` Rich Felker [this message]
2015-09-09 4:47 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150907045044.GY17773@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).