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: <00af01c56c8c$54974c30$1f3ca8c0@AlohaSunset.com> From: "Mark Pizzolato" To: Subject: Multi Threaded programs deadlock doing simple I/O operations Date: Wed, 8 Jun 2005 17:43:59 -0700 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00AC_01C56C51.A6898BB0" X-IsSubscribed: yes ------=_NextPart_000_00AC_01C56C51.A6898BB0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit There is a serious problem for multi threaded programs doing simple I/O operations in cygwin (open, dup, fdopen, fclose, and close). The attached 81 line test program clearly demonstrates the issue (by hanging and no longer consuming CPU or performing any I/O operations). I'm sure that anyone who ever encountered a stange hang in any program running under cygwin would appreciate a fix for this issue. - Mark Pizzolato ------=_NextPart_000_00AC_01C56C51.A6898BB0 Content-Type: text/plain; format=flowed; name="iotest.c"; reply-type=original Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="iotest.c" #include #include #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("%d:", pthread_self()); printf("%s", buf); pthread_mutex_unlock(&log_mutex); } struct TestIoInfo { int Iterations; int Progress; }; void * TestIoThread (void *arg) { struct TestIoInfo *t =3D (struct TestIoInfo *)arg; int i, j; int fd, fdd; char FileName[255]; FILE *f; =09 logit("IO Thread %d starting...\n", pthread_self()); snprintf(FileName, sizeof(FileName), "/tmp/TestIoThread-%d-%x", getpid(), = pthread_self()); sleep(1); for (j=3D0; jIterations; ++j) { if ((fd =3D open(FileName, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0= ) { logit("Error Opening File: %s - %d\n", FileName, errno); return; } fdd =3D dup(fd); if ((f =3D fdopen(fdd, "rb")) =3D=3D NULL) { logit("Can't open descriptor %d - %d\n", fd, errno); return; } fclose(f); close(fd); if (0 =3D=3D (j%t->Progress)) { logit("IO Thread %d - %d\n", pthread_self(), j); } } unlink(FileName); logit("IO Thread %d done.\n", pthread_self()); return NULL; } main (int argc, char ** argv) { int threadcount =3D 4; int progress =3D 1; pthread_t tid[10]; int i; struct TestIoInfo IoInfo; logit("Testing with %d concurrent threads\n", threadcount); logit("Progress indicated every %d operations...\n", progress); IoInfo.Iterations =3D 200; IoInfo.Progress =3D progress; for (i=3D0; i