Author: zoltan
Date: 2005-07-07 12:22:23 -0400 (Thu, 07 Jul 2005)
New Revision: 47046
Modified:
trunk/mono/mono/metadata/ChangeLog
trunk/mono/mono/metadata/threadpool.c
trunk/mono/mono/metadata/threads.c
Log:
2005-07-07 Zoltan Varga <[EMAIL PROTECTED]>
* threads.c (mono_threads_abort_appdomain_threads): Wait for threads to
exit the appdomain as well being aborted.
* threadpool.c: Create all threadpool threads inside the root
appdomain, and
change back to the root domain after calling managed code. This enables
appdomains using threadpools to be unloaded.
Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog 2005-07-07 16:11:24 UTC (rev 47045)
+++ trunk/mono/mono/metadata/ChangeLog 2005-07-07 16:22:23 UTC (rev 47046)
@@ -1,3 +1,12 @@
+2005-07-07 Zoltan Varga <[EMAIL PROTECTED]>
+
+ * threads.c (mono_threads_abort_appdomain_threads): Wait for threads to
+ exit the appdomain as well being aborted.
+
+ * threadpool.c: Create all threadpool threads inside the root
appdomain, and
+ change back to the root domain after calling managed code. This enables
+ appdomains using threadpools to be unloaded.
+
2005-07-07 Martin Baulig <[EMAIL PROTECTED]>
* class-internals.h
Modified: trunk/mono/mono/metadata/threadpool.c
===================================================================
--- trunk/mono/mono/metadata/threadpool.c 2005-07-07 16:11:24 UTC (rev
47045)
+++ trunk/mono/mono/metadata/threadpool.c 2005-07-07 16:22:23 UTC (rev
47046)
@@ -240,16 +240,17 @@
}
domain = ((MonoObject *)ar)->vtable->domain;
+ mono_thread_push_appdomain_ref (domain);
if (mono_domain_set (domain, FALSE)) {
ASyncCall *ac;
- mono_thread_push_appdomain_ref (domain);
mono_async_invoke (ar);
ac = (ASyncCall *) ar->data;
if (ac->msg->exc != NULL)
mono_unhandled_exception (ac->msg->exc);
- mono_thread_pop_appdomain_ref ();
+ mono_domain_set (mono_get_root_domain (), TRUE);
}
+ mono_thread_pop_appdomain_ref ();
InterlockedDecrement (&busy_io_worker_threads);
}
@@ -303,7 +304,7 @@
InterlockedIncrement (&busy_io_worker_threads);
InterlockedIncrement (&io_worker_threads);
domain = ((ares) ? ((MonoObject *) ares)->vtable->domain :
mono_domain_get ());
- mono_thread_create (domain, async_invoke_io_thread, ares);
+ mono_thread_create (mono_get_root_domain (),
async_invoke_io_thread, ares);
} else {
append_job (&io_queue_lock, &async_io_queue, ares);
ReleaseSemaphore (io_job_added, 1, NULL);
@@ -1008,7 +1009,7 @@
InterlockedIncrement (&mono_worker_threads);
InterlockedIncrement (&busy_worker_threads);
domain = ((MonoObject *) ares)->vtable->domain;
- mono_thread_create (domain, async_invoke_thread, ares);
+ mono_thread_create (mono_get_root_domain (),
async_invoke_thread, ares);
} else {
append_job (&mono_delegate_section, &async_call_queue, ares);
ReleaseSemaphore (job_added, 1, NULL);
@@ -1139,21 +1140,22 @@
/* worker threads invokes methods in different domains,
* so we need to set the right domain here */
domain = ((MonoObject *)ar)->vtable->domain;
+ mono_thread_push_appdomain_ref (domain);
if (mono_domain_set (domain, FALSE)) {
ASyncCall *ac;
- mono_thread_push_appdomain_ref (domain);
mono_async_invoke (ar);
ac = (ASyncCall *) ar->data;
if (ac->msg->exc != NULL)
mono_unhandled_exception (ac->msg->exc);
- mono_thread_pop_appdomain_ref ();
+ mono_domain_set (mono_get_root_domain (), TRUE);
}
+ mono_thread_pop_appdomain_ref ();
InterlockedDecrement (&busy_worker_threads);
}
data = dequeue_job (&mono_delegate_section, &async_call_queue);
-
+
if (!data) {
guint32 wr;
int timeout = 10000;
Modified: trunk/mono/mono/metadata/threads.c
===================================================================
--- trunk/mono/mono/metadata/threads.c 2005-07-07 16:11:24 UTC (rev 47045)
+++ trunk/mono/mono/metadata/threads.c 2005-07-07 16:22:23 UTC (rev 47046)
@@ -1470,7 +1470,7 @@
MONO_ARCH_SAVE_REGS;
mono_monitor_enter (thread->synch_lock);
-
+
thread->state &= ~ThreadState_AbortRequested;
if (!thread->abort_exc) {
@@ -1603,7 +1603,7 @@
/* Make sure the thread is awake */
mono_thread_resume (thread);
-
+
thread->state |= ThreadState_StopRequested;
thread->state &= ~ThreadState_AbortRequested;
@@ -2126,11 +2126,12 @@
MonoDomain *domain = data->domain;
if (mono_thread_has_appdomain_ref (thread, domain)) {
- /* printf ("ABORTING THREAD %p BECAUSE IT REFERENCES DOMAIN
%s.\n", thread->tid, domain->friendly_name); */
HANDLE handle = OpenThread (THREAD_ALL_ACCESS, TRUE,
thread->tid);
if (handle == NULL)
return;
+ /* printf ("ABORTING THREAD %p BECAUSE IT REFERENCES DOMAIN
%s.\n", thread->tid, domain->friendly_name); */
+
ves_icall_System_Threading_Thread_Abort (thread, NULL);
if(data->wait.num<MAXIMUM_WAIT_OBJECTS) {
@@ -2168,7 +2169,11 @@
LeaveCriticalSection (&threads_mutex);
if (user_data.wait.num > 0)
- wait_for_tids (&user_data.wait, timeout);
+ /*
+ * We should wait for the threads either to abort, or
to leave the
+ * domain. We can't do the latter, so we wait with a
timeout.
+ */
+ wait_for_tids (&user_data.wait, 100);
/* Update remaining time */
timeout -= GetTickCount () - start_time;
@@ -2601,7 +2606,7 @@
/* The thread may already be stopping */
if (thread == NULL)
return;
-
+
if (thread->interruption_requested && (bypass_abort_protection ||
!is_running_protected_wrapper ())) {
MonoException* exc = mono_thread_execute_interruption (thread);
if (exc) mono_raise_exception (exc);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches