[bug?] 2nd printf output gets gobbled up when 1st used in a thread

Corinna Vinschen corinna-cygwin@cygwin.com
Wed Jan 9 14:25:00 GMT 2013


On Jan  1 16:16, furrylogical wrote:
> Hello everyone,
> 
> Cygwin seems to behave strangely when `printf` is used in threads: if
> the first `printf` encountered occurs in another thread, then the
> first `printf` that occurs in the main function will vanish into thin
> air.  The following fragment illustrates this:
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <pthread.h>
> 
> void *func(void *arg)
> {
>     printf("thread_printf\n");
>     return NULL;
> }
> 
> int main(int argc, char **argv)
> {
>     pthread_t thread;
>     pthread_create(&thread, NULL, func, NULL);
>     pthread_join(thread, NULL);
>     printf("main_printf1\n");           /* This line never gets printed */
>     printf("main_printf2\n");
>     return 0;
> }
> 
> When compiled with `gcc` with no options, the output is:
>   thread_printf
>   main_printf2
> 
> I'm not familiar with the Cygwin codebase.  If someone can point me in
> the right direction, I might be able to figure out what is causing
> this issue.
> 
> I appreciate the if someone can help me figure this out, though I
> understand it's not exactly a critical issue.  Thanks all.

Thanks for the testcase.  I could easily reproduce this issue and
track down the cause.  I checked in a patch.  Please give the next
developer snapshot from http://cygwin.com/snapshots/ a try.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list