From: nobu.nokada@... Date: 2004-02-26T15:44:46+09:00 Subject: Re: thread gurus please help... Hi, At Thu, 26 Feb 2004 13:54:48 +0900, Ara.T.Howard wrote in [ruby-talk:93721]: > what is a 'bean jam ball'? sounds like something good... 'Bean jam' is sweet paste made boiling red beans and sugar. It looks black in common, but there is white one and others. And Japanese are in the habit of eating rice balls with bean jam in each equinox. > i tried replacing with sysread but am now failing with > > sysread for buffered IO (IOError) See [ruby-talk:93722] about sysread. Anyway, I feel non-blocking IO should never block in this case, simpler code which can reproduce your issue. require 'io/nonblock' unless rio = IO.popen("-") loop do p Time.now sleep 1 end end Thread.new do until rio.eof? #Thread.critical = true # blocks w/o this text = rio.nonblock{ rio.read } #Thread.critical = false # blocks w/o this print text end end.join Index: io.c =================================================================== RCS file: /cvs/ruby/src/ruby/io.c,v retrieving revision 1.261 diff -u -2 -p -d -r1.261 io.c --- io.c 25 Feb 2004 12:17:39 -0000 1.261 +++ io.c 26 Feb 2004 06:38:59 -0000 @@ -889,4 +889,10 @@ rb_io_to_io(io) } +#ifndef O_NONBLOCK +# ifdef O_NDELAY +# define O_NONBLOCK O_NDELAY +# endif +#endif + /* reading functions */ long @@ -903,4 +909,8 @@ rb_io_fread(ptr, len, f) long i = READ_DATA_PENDING_COUNT(f); if (i <= 0) { +#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK) + i = fcntl(fileno(f), F_GETFL); + if (i == -1 || (i & O_NONBLOCK)) break; +#endif rb_thread_wait_fd(fileno(f)); i = READ_DATA_PENDING_COUNT(f); @@ -5508,10 +5518,6 @@ Init_IO() rb_file_const("CREAT", INT2FIX(O_CREAT)); rb_file_const("EXCL", INT2FIX(O_EXCL)); -#if defined(O_NDELAY) || defined(O_NONBLOCK) -# ifdef O_NONBLOCK +#ifdef O_NONBLOCK rb_file_const("NONBLOCK", INT2FIX(O_NONBLOCK)); -# else - rb_file_const("NONBLOCK", INT2FIX(O_NDELAY)); -# endif #endif rb_file_const("TRUNC", INT2FIX(O_TRUNC)); -- Nobu Nakada