mailing list of musl libc
 help / color / mirror / code / Atom feed
* process doesn't terminate when closing streams from another thread
@ 2015-09-06 14:44 Nuno Gonçalves
  2015-09-06 17:00 ` Szabolcs Nagy
  2015-09-09  4:47 ` Rich Felker
  0 siblings, 2 replies; 4+ messages in thread
From: Nuno Gonçalves @ 2015-09-06 14:44 UTC (permalink / raw)
  To: musl

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;
   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.

This happens on target-mips_34kc_musl-1.1.11.

Thanks,
Nuno


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: process doesn't terminate when closing streams from another thread
  2015-09-06 14:44 process doesn't terminate when closing streams from another thread Nuno Gonçalves
@ 2015-09-06 17:00 ` Szabolcs Nagy
  2015-09-07  4:50   ` Rich Felker
  2015-09-09  4:47 ` Rich Felker
  1 sibling, 1 reply; 4+ messages in thread
From: Szabolcs Nagy @ 2015-09-06 17:00 UTC (permalink / raw)
  To: musl

* 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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: process doesn't terminate when closing streams from another thread
  2015-09-06 17:00 ` Szabolcs Nagy
@ 2015-09-07  4:50   ` Rich Felker
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2015-09-07  4:50 UTC (permalink / raw)
  To: musl

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: process doesn't terminate when closing streams from another thread
  2015-09-06 14:44 process doesn't terminate when closing streams from another thread Nuno Gonçalves
  2015-09-06 17:00 ` Szabolcs Nagy
@ 2015-09-09  4:47 ` Rich Felker
  1 sibling, 0 replies; 4+ messages in thread
From: Rich Felker @ 2015-09-09  4:47 UTC (permalink / raw)
  To: musl

On Sun, Sep 06, 2015 at 03:44:45PM +0100, Nuno Gonçalves wrote:
> 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;
>    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.
> 
> This happens on target-mips_34kc_musl-1.1.11.
> 
> Thanks,

Thanks for the report. This should now be fixed (in git master). Let
me know if you still have problems.

Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-09  4:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-06 14:44 process doesn't terminate when closing streams from another thread Nuno Gonçalves
2015-09-06 17:00 ` Szabolcs Nagy
2015-09-07  4:50   ` Rich Felker
2015-09-09  4:47 ` Rich Felker

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).