harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Evgueni Brevnov" <evgueni.brev...@gmail.com>
Subject [drlvm][shutdown] Part2: How to shutdown native threads?
Date Thu, 07 Dec 2006 11:31:13 GMT
Hi everybody,

I'd like to continue our discussion regarding  VM shutdown procedure
and resources cleanup. In this particular thread I'd like to talk
about resource cleanup for native threads. For those how missed the
first discussion I can repeat what was proposed to do in case of the
native threads. (Read more here

On 11/20/06, Evgueni Brevnov <evgueni.brevnov@gmail.com> wrote:


> Native threads: It seems there is not much we can do to stop arbitrary
> native thread and release resources owed by it. I don't consider
> global resource management as a possible solution here :-). Thus there
> are two requirements for native threads to ensure safe VM shutdown:
> a) Any native thread must be created by TM or attached to TM. So TM is
> aware about all running native threads.
> b) Native thread provides a callback which is called to request thread
> shutdown. It's the native thread responsibility to clean its resources
> upon shutdown request.


Thread creation and shutdown callback registration operations should
be atomic. In other words, there should be no possibility to shutdown
the thread between these two operations. Thus it seems to be
convenient to pass shutdown callback as a parameter to the
hythread_create & hythread_attach routines. It is how they will look:

* @param[in] callback when non null callback function is specified it will be
*    executed by hythread_cancel(hythread_t thread) to initiate thread shutdown
*    sequence. If no callback is given then this thread doesn't have a chance to
*    cleanup its internals and will be terminated forcibly.
*    Note that by the time of callback execution the VM  is already in shutdown
*    stage thus not all services provided by VM are available. For example,
*    any attempt to create a new java thread or attach the current one
will fail.
* @return  0 on success or negative value on failure
* @see hythread_exit, hythread_resume
IDATA VMCALL  hythread_create (hythread_t *handle, UDATA stacksize,
UDATA priority, UDATA suspend, hythread_entrypoint_t entrypoint, void
*entryarg, hythread_shutdowncallback_t callback);

* @param[in] callback <same as above>
IDATA VMCALL  hythread_attach (hythread_t *handle,
hythread_shutdowncallback_t callback) ;

Also registered shutdown callback should be taken into account by
hythread_cancel(hythread_t thread) and called as appropriate.


On 11/21/06, Tim Ellison <t.p.ellison@gmail.com> wrote:
> <snip>
> However, the resource management API
> we define should be generic, so we can register a callback to such
> third-party libraries if they have a clean-up function we need to call.

I agree, we need to provide the API to third-party libraries. But it
seems like an VMI extension and doesn't have direct intersection with
the proposed API to shutdown native threads. Do I miss something here?


View raw message