Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <009b01c56c45$e36b9930$1f3ca8c0@AlohaSunset.com> From: "Mark Pizzolato" To: Subject: gdb threading troubles Date: Wed, 8 Jun 2005 09:19:33 -0700 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0098_01C56C0B.2EE7F240" X-IsSubscribed: yes ------=_NextPart_000_0098_01C56C0B.2EE7F240 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit The attached example test program runs to completion when run directly, but spins infinitely when run under gdb. I'm compiling with: gcc -g -O0 mutexttest.c -o mutexttest running under: cygwin 1.5.17-1 gdb 20041228-3 ------=_NextPart_000_0098_01C56C0B.2EE7F240 Content-Type: text/plain; format=flowed; name="mutextest.c"; reply-type=original Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="mutextest.c" #include #include #include #include pthread_mutex_t log_mutex =3D PTHREAD_MUTEX_INITIALIZER; void logit(const char *fmt, ...) { va_list args; char buf[1024]; int bytes; =09 buf[sizeof(buf)-1] =3D '\0'; va_start(args, fmt); bytes =3D vsnprintf(buf, sizeof(buf)-1, fmt, args); va_end(args); pthread_mutex_lock(&log_mutex); printf("%s", buf); pthread_mutex_unlock(&log_mutex); } pthread_mutex_t mutex =3D PTHREAD_MUTEX_INITIALIZER; struct TestInfo { void (*Lock)(void); void (*Unlock)(void); int Iterations; int Data; int Increment; }; void NoLock(void) { } void NoUnlock(void) { } void PthreadLock(void) { pthread_mutex_lock(&mutex); } void PthreadUnlock(void) { pthread_mutex_unlock(&mutex); } void * TestThread (void *arg) { struct TestInfo *t =3D (struct TestInfo *)arg; int i; int *pData =3D &t->Data; =09 logit("Thread %d starting...\n", pthread_self()); sleep(1); for (i=3D0; iIterations; ++i) { int tmp; int trand; t->Lock(); srand(46); trand =3D rand(); srand(46); tmp =3D t->Data; tmp =3D tmp + trand - rand(); tmp =3D tmp + t->Increment; t->Data =3D tmp; t->Unlock(); } logit("Thread %d done.\n", pthread_self()); return NULL; } main (int argc, char ** argv) { int threadcount =3D 10; pthread_t tid[10]; int i; struct TestInfo Info; Info.Iterations =3D 500000; Info.Increment =3D 3; =09 Info.Data =3D 0; Info.Unlock =3D &NoUnlock; Info.Lock =3D &NoLock; for (i=3D0; i