hi, On Sun, Feb 05, 2006 at 01:15:15PM +0900, Daishi Kato wrote: > Hi Hans, > > > imho, they should not be commented out, because they are > > needed to tell the scheduler that the thread is waiting > > for some socket to be ready for reading or writing. > > > > the scheduler then only invokes the thread when the > > socket is ready. > > So, is it like a select() call?
yes, the scheduler uses select() internally and unblocks the thread when the fd is ready. this is done in ##sys#unblock-threads-for-i/o, which is called in ##sys#schedule. ##sys#thread-block-for-i/o! doesn't call select() itself, it only registers the fd and sets the thread's state to blocked. > > without the ##sys#thread-block-for-i/o call, the scheduler > > invokes the thread repeatedly, the thread calls recv(), > > gets EWOULDBLOCK and (yield)s again. this wastes a lot of > > cpu time, especially when all threads are waiting for i/o. > > Ah, you are right. This is why it worked on win32. > I guess ##sys#thread-block-for-i/o does not work correctly > on win32, and without it, the thread is invoked repeatedly, > letting the program work WITH lots of cpu time... > > Would there be a piece of code to see if > ##sys#thread-block-for-i/o is really working? i think it would be useful to test a simple program that does (udp-recvfrom) in one thread and maybe prints a message on stdout every second in the main thread. when you run this program with strace (which afaik is also available for windows), you should see if select() is called correctly and what it returns and if recv() behaves correctly and does not block. another option would be to recompile chicken with the dbg macro in scheduler.scm commented in. btw, i noticed, that in tcp.scm, fcntl() is used to set the O_NONBLOCK flag on both unix and windows, while in udp.scm ioctlsocket() is used on windows. does tcp.scm work on windows? maybe udp.scm should also use fcntl() on windows? regards, hans. _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
