Mail Archives: cygwin/2005/06/08/20:44:25
------=_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 <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
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; j<t->Iterations; ++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<threadcount; ++i) {
pthread_create(&tid[i], NULL, TestIoThread, &IoInfo);
}
for (i=3D0; i<threadcount; ++i)
pthread_join(tid[i], NULL);
logit("All Io Threads completed\n");
}
------=_NextPart_000_00AC_01C56C51.A6898BB0
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------=_NextPart_000_00AC_01C56C51.A6898BB0--
- Raw text -