In article <8764uerk3f.fsf / dessyku.is-a-geek.org>, Yohanes Santoso <ysantoso-rubytalk / dessyku.is-a-geek.org> writes: > Disk I/O will always block the process executing it. only way to avoid > that is to have another process do the disk I/O (at least on linux, > *bsd; there used to have a unix that does not have this limitation, > but i can't remember the name). Using native thread also does not help > since the whole process is blocked. I think native (kernel level) thread doesn't block other threads. % uname -a Linux nute 2.6.8-2-686 #1 Thu May 19 17:53:30 JST 2005 i686 GNU/Linux % cat t.c #include <pthread.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #define TMPFILE "/tmp/xx" void *f1(void *arg) { struct stat s; int i, ret; for (i = 0; i < 10; i++) { ret = stat(TMPFILE, &s); if (ret == -1) printf("%d: stat fail\n", i); else printf("%d: %x\n", i, s.st_size); usleep(100000); } } void *f2(void *arg) { #define SIZ 0x10000000 char *buf = malloc(SIZ); int fd; int ret; if (buf == NULL) { perror("malloc"); return NULL; } fd = open(TMPFILE, O_WRONLY|O_CREAT|O_TRUNC, 0666); if (fd == -1) { perror("open"); return NULL; } printf("begin write\n"); ret = write(fd, buf, SIZ); printf("end write %x\n", ret); return NULL; } int main() { pthread_t th1, th2; unlink(TMPFILE); pthread_create(&th1, NULL, f1, NULL); pthread_create(&th2, NULL, f2, NULL); pthread_join(th1, NULL); pthread_join(th2, NULL); return 0; } % gcc t.c -lpthread % ./a.out 0: stat fail begin write 1: 2143000 2: 41a3000 3: 61d9000 4: 8264000 5: a0e8000 6: c08e000 7: e0d3000 end write 10000000 8: 10000000 9: 10000000 -- Tanaka Akira