printf + pthreads+gdb+mintty = hang?

Ryan Johnson ryan.johnson@cs.utoronto.ca
Tue May 7 20:22:00 GMT 2013


Hi all,

Running the attached STC inside gdb hangs (zero CPU util, have to kill 
gdb from Task Manager, killing a.exe doesn't cut it).

Compile line used: g++ -Wall -g -mthreads -DBUG bug.cpp

I currently have the following package versions:
cygwin-1.7.18(0.263/5/3) 2013-04-19
mintty-1.1.3-1
gdb-7.6.50-1
gcc-4.5.3-3

The problem seems to be related to threads calling fprintf inside gdb, 
it runs fine from the command line, or with printf instead; both fprintf 
and printf sometimes trigger "warning: SuspendThread failed. (winerr 6)" 
(not sure if that matters).

Known issue? Easy workaround? New bug?

Thanks,
Ryan

-------------- next part --------------
#include <stdio.h>
#include <pthread.h>

#if BUG
#define P(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#else
#define P(fmt, ...) printf(fmt, ##__VA_ARGS__)
#endif

void* go(void *arg) {
    long tid = (long)arg;
    P("Thread %ld started\n", tid);
    for (int i=0; i < 100; i++) 
        P("%ld\n", tid+i);
    P("Thread %ld exited\n", tid);
    return 0;
}

int main() {
    int tcount = 3;
    pthread_t tids[tcount];
    for (int i=0; i < tcount; i++)
        pthread_create(&tids[i], 0, &go, (void*)(1000*i));
    for (int i=0; i < tcount; i++)
        pthread_join(tids[i], 0);
    return 0;
}

-------------- next part --------------
--
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