This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: do we need separate thread for FirstThread


Bryce McKinlay <bryce@albatross.co.nz> writes:

> > * Avoid creating threads in single-threaded programs.
> 
> Well, we can't really do this, since a separate finalization thread (for
> example) will be required in order to implement finalization correctly.

I'm missing something here.  The JLS says finalizer are run in an
"unspecified" thread.  There seem to be two logical alternatives:
(1) a special finalizer or gc thread, or
(2) the thread that causes gc to be invoked (by doing a new).
Why is (2) prohibited?  Do you mean as a consequence of the boehm-gc
implementation or is there some subtle point about finalization
semantics I don't know about?

> The reason why we have a separate main thread currently is because it is
> simply easier and cleaner to do this way. We have to take into account
> Java daemon threads, which have to keep running even if main() exits, and
> provide a place to implement shutdown hooks (a 1.3 API).

The main thread seems like a good place to do this:

int main (argc, argv)
{
  start_vm();
  JvArray<jstring> jargs = ...;
  MainClass.main(jargs);
  if (threads_started)
    wait_for_non_deamon_threads();
  Runtime::exit(0);
}

> That said, given that we need to solve these problems anyway for the
> invocation interfaces, I have no objection to making the main C thread
> the main Java thread. Its just that it is trickier than you might think

I don't know how our gc interacts with threads, so I can see that
might be non-trivial.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]