From owner-freebsd-java Wed Jan 13 11:14:37 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA04723 for freebsd-java-outgoing; Wed, 13 Jan 1999 11:14:37 -0800 (PST) (envelope-from owner-freebsd-java@FreeBSD.ORG) Received: from ns.mt.sri.com (sri-gw.MT.net [206.127.105.141]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA04651 for ; Wed, 13 Jan 1999 11:14:20 -0800 (PST) (envelope-from nate@mt.sri.com) Received: from mt.sri.com (rocky.mt.sri.com [206.127.76.100]) by ns.mt.sri.com (8.8.8/8.8.8) with SMTP id JAA02568; Wed, 13 Jan 1999 09:50:55 -0700 (MST) (envelope-from nate@rocky.mt.sri.com) Received: by mt.sri.com (SMI-8.6/SMI-SVR4) id JAA27754; Wed, 13 Jan 1999 09:50:54 -0700 Date: Wed, 13 Jan 1999 09:50:54 -0700 Message-Id: <199901131650.JAA27754@mt.sri.com> From: Nate Williams MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Justin Wells Cc: freebsd-java@FreeBSD.ORG Subject: Re: busywait in IOstream code? In-Reply-To: <19990112212038.E2400@semiotek.com> References: <19990112212038.E2400@semiotek.com> X-Mailer: VM 6.34 under 19.16 "Lille" XEmacs Lucid Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org > I have a multithreaded program which normally runs under a web server, > but I have a bunch of command line test harnesses that I run against it, > basically I type in a command and it does something--I use this to debug > my program. > > However, I noticed when doing this that my background threads weren't > ever getting a chance to execute. Doing this in a high priority thread: > > for(;;;) { sleep(someTime); } > > solved the problem (causes a thread scheduling event every someTime msecs). > > I conclude from this that there is some code in IOStream that is > busywaiting and not yielding. All system calls (which involves all I/O) in FreeBSD blocks until it finishes by the very nature of a single-threaded kernel. This is not a JVM problem, but a problem with *ALL* Java implementation which use green-threads, which attempt to emulate kernel threads. By throwing in your high priority thread doing the sleep, it makes the green threads solution a bit more deterministic by kicking the scheduler which attempts to (badly, but better than nothing) allow other threads to be scheduled. In Java on unix, threads are not pre-emptively scheduled, but each thread is allowed to run till whenever it decides to give up (not quite true, but for the most part true). This is the same behavior as on the Solaris 'reference' platform and is not specific to FreeBSD. It's not an issue of busy-waiting, it's an issue of not using pre-emptive multi-tasking (which is not a requirement). For a better description of the above behavior, see the O'Reilly book 'Java Threads' by Oaks et al. Nate To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message