2 * threadpool.c: global thread pool
5 * Dietmar Maurer (dietmar@ximian.com)
6 * Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
9 * Copyright 2004-2010 Novell, Inc (http://www.novell.com)
10 * Copyright 2001 Xamarin Inc (http://www.xamarin.com)
16 #include <mono/metadata/profiler-private.h>
17 #include <mono/metadata/threads.h>
18 #include <mono/metadata/threads-types.h>
19 #include <mono/metadata/threadpool-internals.h>
20 #include <mono/metadata/exception.h>
21 #include <mono/metadata/environment.h>
22 #include <mono/metadata/mono-config.h>
23 #include <mono/metadata/mono-mlist.h>
24 #include <mono/metadata/mono-perfcounters.h>
25 #include <mono/metadata/socket-io.h>
26 #include <mono/metadata/mono-cq.h>
27 #include <mono/metadata/mono-wsq.h>
28 #include <mono/metadata/mono-ptr-array.h>
29 #include <mono/io-layer/io-layer.h>
30 #include <mono/utils/mono-time.h>
31 #include <mono/utils/mono-proclib.h>
32 #include <mono/utils/mono-semaphore.h>
33 #include <mono/utils/atomic.h>
35 #ifdef HAVE_SYS_TIME_H
38 #include <sys/types.h>
44 #ifdef HAVE_SYS_SOCKET_H
45 #include <sys/socket.h>
47 #include <mono/utils/mono-poll.h>
49 #include <sys/epoll.h>
52 #include <sys/event.h>
56 #ifndef DISABLE_SOCKETS
57 #include "mono/io-layer/socket-wrappers.h"
60 #include "threadpool.h"
62 #define THREAD_WANTS_A_BREAK(t) ((t->state & (ThreadState_StopRequested | \
63 ThreadState_SuspendRequested)) != 0)
65 #define SPIN_TRYLOCK(i) (InterlockedCompareExchange (&(i), 1, 0) == 0)
66 #define SPIN_LOCK(i) do { \
67 if (SPIN_TRYLOCK (i)) \
71 #define SPIN_UNLOCK(i) i = 0
72 #define SMALL_STACK (128 * (sizeof (gpointer) / 4) * 1024)
74 /* DEBUG: prints tp data every 2s */
77 /* mono_thread_pool_init called */
78 static volatile int tp_inited;
87 CRITICAL_SECTION io_lock; /* access to sock_to_state */
88 int inited; // 0 -> not initialized , 1->initializing, 2->initialized, 3->cleaned up
89 MonoGHashTable *sock_to_state;
93 void (*modify) (gpointer p, int fd, int operation, int events, gboolean is_new);
94 void (*wait) (gpointer sock_data);
95 void (*shutdown) (gpointer event_data);
98 static SocketIOData socket_io_data;
100 /* Keep in sync with the System.MonoAsyncCall class which provides GC tracking */
103 MonoMethodMessage *msg;
104 MonoMethod *cb_method;
105 MonoDelegate *cb_target;
113 MonoCQ *queue; /* GC root */
115 volatile gint waiting; /* threads waiting for a work item */
118 volatile gint pool_status; /* 0 -> not initialized, 1 -> initialized, 2 -> cleaning up */
119 /* min, max, n and busy -> Interlocked */
120 volatile gint min_threads;
121 volatile gint max_threads;
122 volatile gint nthreads;
123 volatile gint busy_threads;
125 void (*async_invoke) (gpointer data);
126 void *pc_nitems; /* Performance counter for total number of items in added */
127 void *pc_nthreads; /* Performance counter for total number of active threads */
129 volatile gint destroy_thread;
130 volatile gint ignore_times; /* Used when there's a thread being created or destroyed */
131 volatile gint sp_lock; /* spin lock used to protect ignore_times */
132 volatile gint64 last_check;
133 volatile gint64 time_sum;
139 static ThreadPool async_tp;
140 static ThreadPool async_io_tp;
142 static void async_invoke_thread (gpointer data);
143 static MonoObject *mono_async_invoke (ThreadPool *tp, MonoAsyncResult *ares);
144 static void threadpool_free_queue (ThreadPool *tp);
145 static void threadpool_append_job (ThreadPool *tp, MonoObject *ar);
146 static void threadpool_append_jobs (ThreadPool *tp, MonoObject **jobs, gint njobs);
147 static void threadpool_init (ThreadPool *tp, int min_threads, int max_threads, void (*async_invoke) (gpointer));
148 static void threadpool_start_idle_threads (ThreadPool *tp);
149 static void threadpool_kill_idle_threads (ThreadPool *tp);
150 static gboolean threadpool_start_thread (ThreadPool *tp);
151 static void monitor_thread (gpointer data);
152 static void socket_io_cleanup (SocketIOData *data);
153 static MonoObject *get_io_event (MonoMList **list, gint event);
154 static int get_events_from_list (MonoMList *list);
155 static int get_event_from_state (MonoSocketAsyncResult *state);
156 static void check_for_interruption_critical (void);
158 static MonoClass *async_call_klass;
159 static MonoClass *socket_async_call_klass;
160 static MonoClass *process_async_call_klass;
162 static GPtrArray *wsqs;
163 CRITICAL_SECTION wsqs_lock;
164 static gboolean suspended;
167 static MonoThreadPoolFunc tp_start_func;
168 static MonoThreadPoolFunc tp_finish_func;
169 static gpointer tp_hooks_user_data;
170 static MonoThreadPoolItemFunc tp_item_begin_func;
171 static MonoThreadPoolItemFunc tp_item_end_func;
172 static gpointer tp_item_user_data;
182 AIO_OP_RECV_JUST_CALLBACK,
183 AIO_OP_SEND_JUST_CALLBACK,
187 AIO_OP_ACCEPTRECEIVE,
188 AIO_OP_RECEIVE_BUFFERS,
193 #include <mono/metadata/tpool-poll.c>
195 #include <mono/metadata/tpool-epoll.c>
196 #elif defined(USE_KQUEUE_FOR_THREADPOOL)
197 #include <mono/metadata/tpool-kqueue.c>
200 * Functions to check whenever a class is given system class. We need to cache things in MonoDomain since some of the
201 * assemblies can be unloaded.
205 is_system_type (MonoDomain *domain, MonoClass *klass)
207 if (domain->system_image == NULL)
208 domain->system_image = mono_image_loaded ("System");
210 return klass->image == domain->system_image;
214 is_corlib_type (MonoDomain *domain, MonoClass *klass)
216 return klass->image == mono_defaults.corlib;
220 * Note that we call it is_socket_type() where 'socket' refers to the image
221 * that contains the System.Net.Sockets.Socket type.
224 is_socket_type (MonoDomain *domain, MonoClass *klass)
226 return is_system_type (domain, klass);
229 #define check_type_cached(domain, ASSEMBLY, _class, _namespace, _name, loc) do { \
231 return *loc == _class; \
232 if (is_##ASSEMBLY##_type (domain, _class) && !strcmp (_name, _class->name) && !strcmp (_namespace, _class->name_space)) { \
239 #define check_corlib_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, corlib, _class, _namespace, _name, loc)
241 #define check_socket_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, socket, _class, _namespace, _name, loc)
243 #define check_system_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, system, _class, _namespace, _name, loc)
246 is_corlib_asyncresult (MonoDomain *domain, MonoClass *klass)
248 check_corlib_type_cached (domain, klass, "System.Runtime.Remoting.Messaging", "AsyncResult", &domain->corlib_asyncresult_class);
252 is_socket (MonoDomain *domain, MonoClass *klass)
254 check_socket_type_cached (domain, klass, "System.Net.Sockets", "Socket", &domain->socket_class);
258 is_socketasyncresult (MonoDomain *domain, MonoClass *klass)
260 return (klass->nested_in &&
261 is_socket (domain, klass->nested_in) &&
262 !strcmp (klass->name, "SocketAsyncResult"));
266 is_socketasynccall (MonoDomain *domain, MonoClass *klass)
268 return (klass->nested_in &&
269 is_socket (domain, klass->nested_in) &&
270 !strcmp (klass->name, "SocketAsyncCall"));
274 is_appdomainunloaded_exception (MonoDomain *domain, MonoClass *klass)
276 check_corlib_type_cached (domain, klass, "System", "AppDomainUnloadedException", &domain->ad_unloaded_ex_class);
280 is_sd_process (MonoDomain *domain, MonoClass *klass)
282 check_system_type_cached (domain, klass, "System.Diagnostics", "Process", &domain->process_class);
286 is_sdp_asyncreadhandler (MonoDomain *domain, MonoClass *klass)
289 return (klass->nested_in &&
290 is_sd_process (domain, klass->nested_in) &&
291 !strcmp (klass->name, "AsyncReadHandler"));
295 #ifdef DISABLE_SOCKETS
297 #define socket_io_cleanup(x)
300 get_event_from_state (MonoSocketAsyncResult *state)
302 g_assert_not_reached ();
307 get_events_from_list (MonoMList *list)
315 socket_io_cleanup (SocketIOData *data)
317 EnterCriticalSection (&data->io_lock);
318 if (data->inited != 2) {
319 LeaveCriticalSection (&data->io_lock);
323 data->shutdown (data->event_data);
324 LeaveCriticalSection (&data->io_lock);
328 get_event_from_state (MonoSocketAsyncResult *state)
330 switch (state->operation) {
333 case AIO_OP_RECV_JUST_CALLBACK:
334 case AIO_OP_RECEIVEFROM:
335 case AIO_OP_READPIPE:
336 case AIO_OP_ACCEPTRECEIVE:
337 case AIO_OP_RECEIVE_BUFFERS:
340 case AIO_OP_SEND_JUST_CALLBACK:
343 case AIO_OP_SEND_BUFFERS:
344 case AIO_OP_DISCONNECT:
346 default: /* Should never happen */
347 g_message ("get_event_from_state: unknown value in switch!!!");
353 get_events_from_list (MonoMList *list)
355 MonoSocketAsyncResult *state;
358 while (list && (state = (MonoSocketAsyncResult *)mono_mlist_get_data (list))) {
359 events |= get_event_from_state (state);
360 list = mono_mlist_next (list);
366 #define ICALL_RECV(x) ves_icall_System_Net_Sockets_Socket_Receive_internal (\
367 (SOCKET)(gssize)x->handle, x->buffer, x->offset, x->size,\
368 x->socket_flags, &x->error);
370 #define ICALL_SEND(x) ves_icall_System_Net_Sockets_Socket_Send_internal (\
371 (SOCKET)(gssize)x->handle, x->buffer, x->offset, x->size,\
372 x->socket_flags, &x->error);
374 #endif /* !DISABLE_SOCKETS */
377 threadpool_jobs_inc (MonoObject *obj)
380 InterlockedIncrement (&obj->vtable->domain->threadpool_jobs);
384 threadpool_jobs_dec (MonoObject *obj)
392 domain = obj->vtable->domain;
393 remaining_jobs = InterlockedDecrement (&domain->threadpool_jobs);
394 if (remaining_jobs == 0 && domain->cleanup_semaphore) {
395 ReleaseSemaphore (domain->cleanup_semaphore, 1, NULL);
402 get_io_event (MonoMList **list, gint event)
412 state = mono_mlist_get_data (current);
413 if (get_event_from_state ((MonoSocketAsyncResult *) state) == event)
418 current = mono_mlist_next (current);
423 mono_mlist_set_next (prev, mono_mlist_next (current));
425 *list = mono_mlist_next (*list);
433 * select/poll wake up when a socket is closed, but epoll just removes
434 * the socket from its internal list without notification.
437 mono_thread_pool_remove_socket (int sock)
440 MonoSocketAsyncResult *state;
443 if (socket_io_data.inited == 0)
446 EnterCriticalSection (&socket_io_data.io_lock);
447 if (socket_io_data.sock_to_state == NULL) {
448 LeaveCriticalSection (&socket_io_data.io_lock);
451 list = mono_g_hash_table_lookup (socket_io_data.sock_to_state, GINT_TO_POINTER (sock));
453 mono_g_hash_table_remove (socket_io_data.sock_to_state, GINT_TO_POINTER (sock));
454 LeaveCriticalSection (&socket_io_data.io_lock);
457 state = (MonoSocketAsyncResult *) mono_mlist_get_data (list);
458 if (state->operation == AIO_OP_RECEIVE)
459 state->operation = AIO_OP_RECV_JUST_CALLBACK;
460 else if (state->operation == AIO_OP_SEND)
461 state->operation = AIO_OP_SEND_JUST_CALLBACK;
463 ares = get_io_event (&list, MONO_POLLIN);
464 threadpool_append_job (&async_io_tp, ares);
466 ares = get_io_event (&list, MONO_POLLOUT);
467 threadpool_append_job (&async_io_tp, ares);
473 init_event_system (SocketIOData *data)
476 if (data->event_system == EPOLL_BACKEND) {
477 data->event_data = tp_epoll_init (data);
478 if (data->event_data == NULL) {
479 if (g_getenv ("MONO_DEBUG"))
480 g_message ("Falling back to poll()");
481 data->event_system = POLL_BACKEND;
484 #elif defined(USE_KQUEUE_FOR_THREADPOOL)
485 if (data->event_system == KQUEUE_BACKEND)
486 data->event_data = tp_kqueue_init (data);
488 if (data->event_system == POLL_BACKEND)
489 data->event_data = tp_poll_init (data);
493 socket_io_init (SocketIOData *data)
497 if (data->inited >= 2) // 2 -> initialized, 3-> cleaned up
500 inited = InterlockedCompareExchange (&data->inited, 1, 0);
503 if (data->inited >= 2)
509 EnterCriticalSection (&data->io_lock);
510 data->sock_to_state = mono_g_hash_table_new_type (g_direct_hash, g_direct_equal, MONO_HASH_VALUE_GC);
512 data->event_system = EPOLL_BACKEND;
513 #elif defined(USE_KQUEUE_FOR_THREADPOOL)
514 data->event_system = KQUEUE_BACKEND;
516 data->event_system = POLL_BACKEND;
518 if (g_getenv ("MONO_DISABLE_AIO") != NULL)
519 data->event_system = POLL_BACKEND;
521 init_event_system (data);
522 mono_thread_create_internal (mono_get_root_domain (), data->wait, data, TRUE, FALSE, SMALL_STACK);
523 LeaveCriticalSection (&data->io_lock);
525 threadpool_start_thread (&async_io_tp);
529 socket_io_add (MonoAsyncResult *ares, MonoSocketAsyncResult *state)
532 SocketIOData *data = &socket_io_data;
537 socket_io_init (&socket_io_data);
538 if (mono_runtime_is_shutting_down () || data->inited == 3 || data->sock_to_state == NULL)
540 if (async_tp.pool_status == 2)
543 MONO_OBJECT_SETREF (state, ares, ares);
545 fd = GPOINTER_TO_INT (state->handle);
546 EnterCriticalSection (&data->io_lock);
547 if (data->sock_to_state == NULL) {
548 LeaveCriticalSection (&data->io_lock);
551 list = mono_g_hash_table_lookup (data->sock_to_state, GINT_TO_POINTER (fd));
553 list = mono_mlist_alloc ((MonoObject*)state);
556 list = mono_mlist_append (list, (MonoObject*)state);
560 mono_g_hash_table_replace (data->sock_to_state, state->handle, list);
561 ievt = get_events_from_list (list);
562 /* The modify function leaves the io_lock critical section. */
563 data->modify (data, fd, state->operation, ievt, is_new);
566 #ifndef DISABLE_SOCKETS
568 socket_io_filter (MonoObject *target, MonoObject *state)
571 MonoSocketAsyncResult *sock_res;
575 if (target == NULL || state == NULL)
578 domain = target->vtable->domain;
579 klass = target->vtable->klass;
580 if (socket_async_call_klass == NULL && is_socketasynccall (domain, klass))
581 socket_async_call_klass = klass;
583 if (process_async_call_klass == NULL && is_sdp_asyncreadhandler (domain, klass))
584 process_async_call_klass = klass;
586 if (klass != socket_async_call_klass && klass != process_async_call_klass)
589 sock_res = (MonoSocketAsyncResult *) state;
590 op = sock_res->operation;
591 if (op < AIO_OP_FIRST || op >= AIO_OP_LAST)
596 #endif /* !DISABLE_SOCKETS */
598 /* Returns the exception thrown when invoking, if any */
600 mono_async_invoke (ThreadPool *tp, MonoAsyncResult *ares)
602 ASyncCall *ac = (ASyncCall *)ares->object_data;
603 MonoObject *res, *exc = NULL;
604 MonoArray *out_args = NULL;
605 HANDLE wait_event = NULL;
606 MonoInternalThread *thread = mono_thread_internal_current ();
608 if (ares->execution_context) {
609 /* use captured ExecutionContext (if available) */
610 MONO_OBJECT_SETREF (ares, original_context, mono_thread_get_execution_context ());
611 mono_thread_set_execution_context (ares->execution_context);
613 ares->original_context = NULL;
617 /* Fast path from ThreadPool.*QueueUserWorkItem */
618 void *pa = ares->async_state;
619 /* The debugger needs this */
620 thread->async_invoke_method = ((MonoDelegate*)ares->async_delegate)->method;
621 res = mono_runtime_delegate_invoke (ares->async_delegate, &pa, &exc);
622 thread->async_invoke_method = NULL;
624 MonoObject *cb_exc = NULL;
627 res = mono_message_invoke (ares->async_delegate, ac->msg, &exc, &out_args);
628 MONO_OBJECT_SETREF (ac, res, res);
629 MONO_OBJECT_SETREF (ac, msg->exc, exc);
630 MONO_OBJECT_SETREF (ac, out_args, out_args);
632 mono_monitor_enter ((MonoObject *) ares);
634 if (ares->handle != NULL)
635 wait_event = mono_wait_handle_get_handle ((MonoWaitHandle *) ares->handle);
636 mono_monitor_exit ((MonoObject *) ares);
637 /* notify listeners */
638 if (wait_event != NULL)
639 SetEvent (wait_event);
641 /* call async callback if cb_method != null*/
642 if (ac != NULL && ac->cb_method) {
645 thread->async_invoke_method = ac->cb_method;
646 mono_runtime_invoke (ac->cb_method, ac->cb_target, pa, &cb_exc);
647 thread->async_invoke_method = NULL;
654 /* restore original thread execution context if flow isn't suppressed, i.e. non null */
655 if (ares->original_context) {
656 mono_thread_set_execution_context (ares->original_context);
657 ares->original_context = NULL;
663 threadpool_start_idle_threads (ThreadPool *tp)
668 stack_size = (!tp->is_io) ? 0 : SMALL_STACK;
672 if (n >= tp->min_threads)
674 if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n)
677 #ifndef DISABLE_PERFCOUNTERS
678 mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
680 mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, FALSE, stack_size);
686 threadpool_init (ThreadPool *tp, int min_threads, int max_threads, void (*async_invoke) (gpointer))
688 memset (tp, 0, sizeof (ThreadPool));
689 tp->min_threads = min_threads;
690 tp->max_threads = max_threads;
691 tp->async_invoke = async_invoke;
692 tp->queue = mono_cq_create ();
693 MONO_SEM_INIT (&tp->new_job, 0);
696 #ifndef DISABLE_PERFCOUNTERS
698 init_perf_counter (const char *category, const char *counter)
700 MonoString *category_str;
701 MonoString *counter_str;
707 if (category == NULL || counter == NULL)
709 root = mono_get_root_domain ();
710 category_str = mono_string_new (root, category);
711 counter_str = mono_string_new (root, counter);
712 machine = mono_string_new (root, ".");
713 return mono_perfcounter_get_impl (category_str, counter_str, NULL, machine, &type, &custom);
719 print_pool_info (ThreadPool *tp)
722 // if (tp->tail - tp->head == 0)
725 g_print ("Pool status? %d\n", InterlockedCompareExchange (&tp->pool_status, 0, 0));
726 g_print ("Min. threads: %d\n", InterlockedCompareExchange (&tp->min_threads, 0, 0));
727 g_print ("Max. threads: %d\n", InterlockedCompareExchange (&tp->max_threads, 0, 0));
728 g_print ("nthreads: %d\n", InterlockedCompareExchange (&tp->nthreads, 0, 0));
729 g_print ("busy threads: %d\n", InterlockedCompareExchange (&tp->busy_threads, 0, 0));
730 g_print ("Waiting: %d\n", InterlockedCompareExchange (&tp->waiting, 0, 0));
731 g_print ("Queued: %d\n", (tp->tail - tp->head));
732 if (tp == &async_tp) {
734 EnterCriticalSection (&wsqs_lock);
735 for (i = 0; i < wsqs->len; i++) {
736 g_print ("\tWSQ %d: %d\n", i, mono_wsq_count (g_ptr_array_index (wsqs, i)));
738 LeaveCriticalSection (&wsqs_lock);
740 g_print ("\tSockets: %d\n", mono_g_hash_table_size (socket_io_data.sock_to_state));
742 g_print ("-------------\n");
746 signal_handler (int signo)
751 g_print ("\n-----Non-IO-----\n");
752 print_pool_info (tp);
754 g_print ("\n-----IO-----\n");
755 print_pool_info (tp);
761 monitor_thread (gpointer unused)
763 ThreadPool *pools [2];
764 MonoInternalThread *thread;
769 pools [0] = &async_tp;
770 pools [1] = &async_io_tp;
771 thread = mono_thread_internal_current ();
772 ves_icall_System_Threading_Thread_SetName_internal (thread, mono_string_new (mono_domain_get (), "Threadpool monitor"));
775 i = 10; //number of spurious awakes we tolerate before doing a round of rebalancing.
778 ts = mono_msec_ticks ();
779 if (SleepEx (ms, TRUE) == 0)
781 ms -= (mono_msec_ticks () - ts);
782 if (mono_runtime_is_shutting_down ())
784 if (THREAD_WANTS_A_BREAK (thread))
785 mono_thread_interruption_checkpoint ();
786 } while (ms > 0 && i--);
788 if (mono_runtime_is_shutting_down ())
794 for (i = 0; i < 2; i++) {
799 need_one = (mono_cq_count (tp->queue) > 0);
800 if (!need_one && !tp->is_io) {
801 EnterCriticalSection (&wsqs_lock);
802 for (i = 0; wsqs != NULL && i < wsqs->len; i++) {
804 wsq = g_ptr_array_index (wsqs, i);
805 if (mono_wsq_count (wsq) != 0) {
810 LeaveCriticalSection (&wsqs_lock);
813 threadpool_start_thread (tp);
819 mono_thread_pool_init_tls (void)
825 mono_thread_pool_init (void)
827 gint threads_per_cpu = 1;
829 gint cpu_count = mono_cpu_count ();
835 result = InterlockedCompareExchange (&tp_inited, 1, 0);
844 MONO_GC_REGISTER_ROOT_FIXED (socket_io_data.sock_to_state);
845 InitializeCriticalSection (&socket_io_data.io_lock);
846 if (g_getenv ("MONO_THREADS_PER_CPU") != NULL) {
847 threads_per_cpu = atoi (g_getenv ("MONO_THREADS_PER_CPU"));
848 if (threads_per_cpu < 1)
852 thread_count = MIN (cpu_count * threads_per_cpu, 100 * cpu_count);
853 threadpool_init (&async_tp, thread_count, MAX (100 * cpu_count, thread_count), async_invoke_thread);
854 threadpool_init (&async_io_tp, cpu_count * 2, cpu_count * 4, async_invoke_thread);
855 async_io_tp.is_io = TRUE;
857 async_call_klass = mono_class_from_name (mono_defaults.corlib, "System", "MonoAsyncCall");
858 g_assert (async_call_klass);
860 InitializeCriticalSection (&wsqs_lock);
861 wsqs = g_ptr_array_sized_new (MAX (100 * cpu_count, thread_count));
863 #ifndef DISABLE_PERFCOUNTERS
864 async_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "Work Items Added");
865 g_assert (async_tp.pc_nitems);
867 async_io_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "IO Work Items Added");
868 g_assert (async_io_tp.pc_nitems);
870 async_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of Threads");
871 g_assert (async_tp.pc_nthreads);
873 async_io_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of IO Threads");
874 g_assert (async_io_tp.pc_nthreads);
878 signal (SIGALRM, signal_handler);
883 static MonoAsyncResult *
884 create_simple_asyncresult (MonoObject *target, MonoObject *state)
886 MonoDomain *domain = mono_domain_get ();
887 MonoAsyncResult *ares;
889 /* Don't call mono_async_result_new() to avoid capturing the context */
890 ares = (MonoAsyncResult *) mono_object_new (domain, mono_defaults.asyncresult_class);
891 MONO_OBJECT_SETREF (ares, async_delegate, target);
892 MONO_OBJECT_SETREF (ares, async_state, state);
897 icall_append_io_job (MonoObject *target, MonoSocketAsyncResult *state)
899 MonoAsyncResult *ares;
901 ares = create_simple_asyncresult (target, (MonoObject *) state);
902 socket_io_add (ares, state);
906 mono_thread_pool_add (MonoObject *target, MonoMethodMessage *msg, MonoDelegate *async_callback,
909 MonoDomain *domain = mono_domain_get ();
910 MonoAsyncResult *ares;
913 ac = (ASyncCall*)mono_object_new (domain, async_call_klass);
914 MONO_OBJECT_SETREF (ac, msg, msg);
915 MONO_OBJECT_SETREF (ac, state, state);
917 if (async_callback) {
918 ac->cb_method = mono_get_delegate_invoke (((MonoObject *)async_callback)->vtable->klass);
919 MONO_OBJECT_SETREF (ac, cb_target, async_callback);
922 ares = mono_async_result_new (domain, NULL, ac->state, NULL, (MonoObject*)ac);
923 MONO_OBJECT_SETREF (ares, async_delegate, target);
925 #ifndef DISABLE_SOCKETS
926 if (socket_io_filter (target, state)) {
927 socket_io_add (ares, (MonoSocketAsyncResult *) state);
931 threadpool_append_job (&async_tp, (MonoObject *) ares);
936 mono_thread_pool_finish (MonoAsyncResult *ares, MonoArray **out_args, MonoObject **exc)
944 /* check if already finished */
945 mono_monitor_enter ((MonoObject *) ares);
947 if (ares->endinvoke_called) {
948 *exc = (MonoObject *) mono_get_exception_invalid_operation (NULL);
949 mono_monitor_exit ((MonoObject *) ares);
953 ares->endinvoke_called = 1;
954 /* wait until we are really finished */
955 if (!ares->completed) {
956 if (ares->handle == NULL) {
957 wait_event = CreateEvent (NULL, TRUE, FALSE, NULL);
958 g_assert(wait_event != 0);
959 MONO_OBJECT_SETREF (ares, handle, (MonoObject *) mono_wait_handle_new (mono_object_domain (ares), wait_event));
961 wait_event = mono_wait_handle_get_handle ((MonoWaitHandle *) ares->handle);
963 mono_monitor_exit ((MonoObject *) ares);
964 WaitForSingleObjectEx (wait_event, INFINITE, TRUE);
966 mono_monitor_exit ((MonoObject *) ares);
969 ac = (ASyncCall *) ares->object_data;
970 g_assert (ac != NULL);
971 *exc = ac->msg->exc; /* FIXME: GC add write barrier */
972 *out_args = ac->out_args;
978 threadpool_kill_idle_threads (ThreadPool *tp)
982 n = (gint) InterlockedCompareExchange (&tp->max_threads, 0, -1);
985 MONO_SEM_POST (&tp->new_job);
990 mono_thread_pool_cleanup (void)
992 if (InterlockedExchange (&async_io_tp.pool_status, 2) == 1) {
993 socket_io_cleanup (&socket_io_data); /* Empty when DISABLE_SOCKETS is defined */
994 threadpool_kill_idle_threads (&async_io_tp);
997 if (async_io_tp.queue != NULL) {
998 MONO_SEM_DESTROY (&async_io_tp.new_job);
999 threadpool_free_queue (&async_io_tp);
1003 if (InterlockedExchange (&async_tp.pool_status, 2) == 1) {
1004 threadpool_kill_idle_threads (&async_tp);
1005 threadpool_free_queue (&async_tp);
1009 EnterCriticalSection (&wsqs_lock);
1010 mono_wsq_cleanup ();
1012 g_ptr_array_free (wsqs, TRUE);
1014 LeaveCriticalSection (&wsqs_lock);
1015 MONO_SEM_DESTROY (&async_tp.new_job);
1020 threadpool_start_thread (ThreadPool *tp)
1025 stack_size = (!tp->is_io) ? 0 : SMALL_STACK;
1026 while (!mono_runtime_is_shutting_down () && (n = tp->nthreads) < tp->max_threads) {
1027 if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n) {
1028 #ifndef DISABLE_PERFCOUNTERS
1029 mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
1031 mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, FALSE, stack_size);
1040 pulse_on_new_job (ThreadPool *tp)
1043 MONO_SEM_POST (&tp->new_job);
1047 icall_append_job (MonoObject *ar)
1049 threadpool_append_jobs (&async_tp, &ar, 1);
1053 threadpool_append_job (ThreadPool *tp, MonoObject *ar)
1055 threadpool_append_jobs (tp, &ar, 1);
1059 threadpool_append_jobs (ThreadPool *tp, MonoObject **jobs, gint njobs)
1061 static int job_counter;
1065 if (mono_runtime_is_shutting_down ())
1068 if (tp->pool_status == 0 && InterlockedCompareExchange (&tp->pool_status, 1, 0) == 0) {
1070 mono_thread_create_internal (mono_get_root_domain (), monitor_thread, NULL, TRUE, FALSE, SMALL_STACK);
1071 threadpool_start_thread (tp);
1073 /* Create on demand up to min_threads to avoid startup penalty for apps that don't use
1074 * the threadpool that much
1076 if (mono_config_is_server_mode ()) {
1077 mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, tp, TRUE, FALSE, SMALL_STACK);
1081 for (i = 0; i < njobs; i++) {
1083 if (ar == NULL || mono_domain_is_unloading (ar->vtable->domain))
1084 continue; /* Might happen when cleaning domain jobs */
1085 if (!tp->is_io && (InterlockedIncrement (&job_counter) % 10) == 0) {
1086 MonoAsyncResult *o = (MonoAsyncResult *) ar;
1087 o->add_time = mono_100ns_ticks ();
1089 threadpool_jobs_inc (ar);
1090 #ifndef DISABLE_PERFCOUNTERS
1091 mono_perfcounter_update_value (tp->pc_nitems, TRUE, 1);
1093 if (!tp->is_io && mono_wsq_local_push (ar))
1096 mono_cq_enqueue (tp->queue, ar);
1099 for (i = 0; tp->waiting > 0 && i < MIN(njobs, tp->max_threads); i++)
1100 pulse_on_new_job (tp);
1104 threadpool_clear_queue (ThreadPool *tp, MonoDomain *domain)
1107 MonoMList *other = NULL;
1108 MonoCQ *queue = tp->queue;
1113 while (mono_cq_dequeue (queue, &obj)) {
1116 if (obj->vtable->domain != domain)
1117 other = mono_mlist_prepend (other, obj);
1118 threadpool_jobs_dec (obj);
1121 if (mono_runtime_is_shutting_down ())
1125 threadpool_append_job (tp, (MonoObject *) mono_mlist_get_data (other));
1126 other = mono_mlist_next (other);
1131 remove_sockstate_for_domain (gpointer key, gpointer value, gpointer user_data)
1133 MonoMList *list = value;
1134 gboolean remove = FALSE;
1136 MonoObject *data = mono_mlist_get_data (list);
1137 if (mono_object_domain (data) == user_data) {
1139 mono_mlist_set_data (list, NULL);
1141 list = mono_mlist_next (list);
1143 //FIXME is there some sort of additional unregistration we need to perform here?
1148 * Clean up the threadpool of all domain jobs.
1149 * Can only be called as part of the domain unloading process as
1150 * it will wait for all jobs to be visible to the interruption code.
1153 mono_thread_pool_remove_domain_jobs (MonoDomain *domain, int timeout)
1157 guint32 start_time = 0;
1159 g_assert (domain->state == MONO_APPDOMAIN_UNLOADING);
1161 threadpool_clear_queue (&async_tp, domain);
1162 threadpool_clear_queue (&async_io_tp, domain);
1164 EnterCriticalSection (&socket_io_data.io_lock);
1165 if (socket_io_data.sock_to_state)
1166 mono_g_hash_table_foreach_remove (socket_io_data.sock_to_state, remove_sockstate_for_domain, domain);
1168 LeaveCriticalSection (&socket_io_data.io_lock);
1171 * There might be some threads out that could be about to execute stuff from the given domain.
1172 * We avoid that by setting up a semaphore to be pulsed by the thread that reaches zero.
1174 sem_handle = CreateSemaphore (NULL, 0, 1, NULL);
1176 domain->cleanup_semaphore = sem_handle;
1178 * The memory barrier here is required to have global ordering between assigning to cleanup_semaphone
1179 * and reading threadpool_jobs.
1180 * Otherwise this thread could read a stale version of threadpool_jobs and wait forever.
1182 mono_memory_write_barrier ();
1184 if (domain->threadpool_jobs && timeout != -1)
1185 start_time = mono_msec_ticks ();
1186 while (domain->threadpool_jobs) {
1187 WaitForSingleObject (sem_handle, timeout);
1188 if (timeout != -1 && (mono_msec_ticks () - start_time) > timeout) {
1194 domain->cleanup_semaphore = NULL;
1195 CloseHandle (sem_handle);
1200 threadpool_free_queue (ThreadPool *tp)
1202 mono_cq_destroy (tp->queue);
1207 mono_thread_pool_is_queue_array (MonoArray *o)
1209 // gpointer obj = o;
1211 // FIXME: need some fix in sgen code.
1221 EnterCriticalSection (&wsqs_lock);
1222 wsq = mono_wsq_create ();
1224 LeaveCriticalSection (&wsqs_lock);
1227 for (i = 0; i < wsqs->len; i++) {
1228 if (g_ptr_array_index (wsqs, i) == NULL) {
1229 wsqs->pdata [i] = wsq;
1230 LeaveCriticalSection (&wsqs_lock);
1234 g_ptr_array_add (wsqs, wsq);
1235 LeaveCriticalSection (&wsqs_lock);
1240 remove_wsq (MonoWSQ *wsq)
1247 EnterCriticalSection (&wsqs_lock);
1249 LeaveCriticalSection (&wsqs_lock);
1252 g_ptr_array_remove_fast (wsqs, wsq);
1255 * Only clean this up when shutting down, any other case will error out
1256 * if we're removing a queue that still has work items.
1258 if (mono_runtime_is_shutting_down ()) {
1259 while (mono_wsq_local_pop (&data)) {
1260 threadpool_jobs_dec (data);
1264 mono_wsq_destroy (wsq);
1265 LeaveCriticalSection (&wsqs_lock);
1269 try_steal (MonoWSQ *local_wsq, gpointer *data, gboolean retry)
1274 if (wsqs == NULL || data == NULL || *data != NULL)
1279 if (mono_runtime_is_shutting_down ())
1282 EnterCriticalSection (&wsqs_lock);
1283 for (i = 0; wsqs != NULL && i < wsqs->len; i++) {
1286 wsq = wsqs->pdata [i];
1287 if (wsq == local_wsq || mono_wsq_count (wsq) == 0)
1289 mono_wsq_try_steal (wsqs->pdata [i], data, ms);
1290 if (*data != NULL) {
1291 LeaveCriticalSection (&wsqs_lock);
1295 LeaveCriticalSection (&wsqs_lock);
1297 } while (retry && ms < 11);
1301 dequeue_or_steal (ThreadPool *tp, gpointer *data, MonoWSQ *local_wsq)
1303 MonoCQ *queue = tp->queue;
1304 if (mono_runtime_is_shutting_down () || !queue)
1306 mono_cq_dequeue (queue, (MonoObject **) data);
1307 if (!tp->is_io && !*data)
1308 try_steal (local_wsq, data, FALSE);
1309 return (*data != NULL);
1313 process_idle_times (ThreadPool *tp, gint64 t)
1317 gboolean compute_avg;
1321 if (tp->ignore_times || t <= 0)
1324 compute_avg = FALSE;
1325 ticks = mono_100ns_ticks ();
1327 SPIN_LOCK (tp->sp_lock);
1328 if (tp->ignore_times) {
1329 SPIN_UNLOCK (tp->sp_lock);
1334 if (tp->last_check == 0)
1335 tp->last_check = ticks;
1336 else if (tp->last_check > 0 && (ticks - tp->last_check) > 5000000) {
1337 tp->ignore_times = 1;
1340 SPIN_UNLOCK (tp->sp_lock);
1345 //printf ("Items: %d Time elapsed: %.3fs\n", tp->n_sum, (ticks - tp->last_check) / 10000.0);
1346 tp->last_check = ticks;
1348 avg = tp->time_sum / tp->n_sum;
1349 if (tp->averages [1] == 0) {
1350 tp->averages [1] = avg;
1352 per1 = ((100 * (ABS (avg - tp->averages [1]))) / tp->averages [1]);
1354 if (avg > tp->averages [1]) {
1355 if (tp->averages [1] < tp->averages [0]) {
1360 } else if (avg < tp->averages [1] && tp->averages [1] < tp->averages [0]) {
1365 min = tp->min_threads;
1367 if ((n - min) < min && tp->busy_threads == n)
1371 if (new_threads != 0) {
1372 printf ("n: %d per1: %lld avg=%lld avg1=%lld avg0=%lld\n", new_threads, per1, avg, tp->averages [1], tp->averages [0]);
1380 tp->averages [0] = tp->averages [1];
1381 tp->averages [1] = avg;
1382 tp->ignore_times = 0;
1384 if (new_threads == -1) {
1385 if (tp->destroy_thread == 0 && InterlockedCompareExchange (&tp->destroy_thread, 1, 0) == 0)
1386 pulse_on_new_job (tp);
1391 should_i_die (ThreadPool *tp)
1393 gboolean result = FALSE;
1394 if (tp->destroy_thread == 1 && InterlockedCompareExchange (&tp->destroy_thread, 0, 1) == 1)
1395 result = (tp->nthreads > tp->min_threads);
1400 set_tp_thread_info (ThreadPool *tp)
1403 MonoInternalThread *thread = mono_thread_internal_current ();
1405 mono_profiler_thread_start (thread->tid);
1406 name = (tp->is_io) ? "IO Threadpool worker" : "Threadpool worker";
1407 mono_thread_set_name_internal (thread, mono_string_new (mono_domain_get (), name), FALSE);
1411 clear_thread_state (void)
1413 MonoInternalThread *thread = mono_thread_internal_current ();
1414 /* If the callee changes the background status, set it back to TRUE */
1415 mono_thread_clr_state (thread , ~ThreadState_Background);
1416 if (!mono_thread_test_state (thread , ThreadState_Background))
1417 ves_icall_System_Threading_Thread_SetState (thread, ThreadState_Background);
1421 check_for_interruption_critical (void)
1423 MonoInternalThread *thread;
1424 /*RULE NUMBER ONE OF SKIP_THREAD: NEVER POKE MANAGED STATE.*/
1425 mono_gc_set_skip_thread (FALSE);
1427 thread = mono_thread_internal_current ();
1428 if (THREAD_WANTS_A_BREAK (thread))
1429 mono_thread_interruption_checkpoint ();
1431 /*RULE NUMBER TWO OF SKIP_THREAD: READ RULE NUMBER ONE.*/
1432 mono_gc_set_skip_thread (TRUE);
1436 fire_profiler_thread_end (void)
1438 MonoInternalThread *thread = mono_thread_internal_current ();
1439 mono_profiler_thread_end (thread->tid);
1443 async_invoke_thread (gpointer data)
1455 set_tp_thread_info (tp);
1458 tp_start_func (tp_hooks_user_data);
1462 MonoAsyncResult *ar;
1464 gboolean is_io_task;
1469 ar = (MonoAsyncResult *) data;
1471 InterlockedIncrement (&tp->busy_threads);
1472 domain = ((MonoObject *)ar)->vtable->domain;
1473 #ifndef DISABLE_SOCKETS
1474 klass = ((MonoObject *) data)->vtable->klass;
1475 is_io_task = !is_corlib_asyncresult (domain, klass);
1478 MonoSocketAsyncResult *state = (MonoSocketAsyncResult *) data;
1479 is_socket = is_socketasyncresult (domain, klass);
1481 switch (state->operation) {
1482 case AIO_OP_RECEIVE:
1483 state->total = ICALL_RECV (state);
1486 state->total = ICALL_SEND (state);
1491 /* worker threads invokes methods in different domains,
1492 * so we need to set the right domain here */
1495 if (mono_domain_is_unloading (domain) || mono_runtime_is_shutting_down ()) {
1496 threadpool_jobs_dec ((MonoObject *)ar);
1499 InterlockedDecrement (&tp->busy_threads);
1501 mono_thread_push_appdomain_ref (domain);
1502 if (threadpool_jobs_dec ((MonoObject *)ar)) {
1505 mono_thread_pop_appdomain_ref ();
1506 InterlockedDecrement (&tp->busy_threads);
1510 if (mono_domain_set (domain, FALSE)) {
1513 if (tp_item_begin_func)
1514 tp_item_begin_func (tp_item_user_data);
1516 if (!is_io_task && ar->add_time > 0)
1517 process_idle_times (tp, ar->add_time);
1518 exc = mono_async_invoke (tp, ar);
1519 if (tp_item_end_func)
1520 tp_item_end_func (tp_item_user_data);
1522 mono_internal_thread_unhandled_exception (exc);
1523 if (is_socket && tp->is_io) {
1524 MonoSocketAsyncResult *state = (MonoSocketAsyncResult *) data;
1526 if (state->completed && state->callback) {
1527 MonoAsyncResult *cb_ares;
1528 cb_ares = create_simple_asyncresult ((MonoObject *) state->callback,
1529 (MonoObject *) state);
1530 icall_append_job ((MonoObject *) cb_ares);
1533 mono_domain_set (mono_get_root_domain (), TRUE);
1535 mono_thread_pop_appdomain_ref ();
1536 InterlockedDecrement (&tp->busy_threads);
1537 clear_thread_state ();
1543 must_die = should_i_die (tp);
1544 if (!must_die && (tp->is_io || !mono_wsq_local_pop (&data)))
1545 dequeue_or_steal (tp, &data, wsq);
1548 while (!must_die && !data && n_naps < 4) {
1551 InterlockedIncrement (&tp->waiting);
1553 // Another thread may have added a job into its wsq since the last call to dequeue_or_steal
1554 // Check all the queues again before entering the wait loop
1555 dequeue_or_steal (tp, &data, wsq);
1557 InterlockedDecrement (&tp->waiting);
1561 mono_gc_set_skip_thread (TRUE);
1563 #if defined(__OpenBSD__)
1564 while (mono_cq_count (tp->queue) == 0 && (res = mono_sem_wait (&tp->new_job, TRUE)) == -1) {// && errno == EINTR) {
1566 while (mono_cq_count (tp->queue) == 0 && (res = mono_sem_timedwait (&tp->new_job, 2000, TRUE)) == -1) {// && errno == EINTR) {
1568 if (mono_runtime_is_shutting_down ())
1570 check_for_interruption_critical ();
1572 InterlockedDecrement (&tp->waiting);
1574 mono_gc_set_skip_thread (FALSE);
1576 if (mono_runtime_is_shutting_down ())
1578 must_die = should_i_die (tp);
1579 dequeue_or_steal (tp, &data, wsq);
1583 if (!data && !tp->is_io && !mono_runtime_is_shutting_down ()) {
1584 mono_wsq_local_pop (&data);
1585 if (data && must_die) {
1586 InterlockedCompareExchange (&tp->destroy_thread, 1, 0);
1587 pulse_on_new_job (tp);
1596 down = mono_runtime_is_shutting_down ();
1597 if (!down && nt <= tp->min_threads)
1599 if (down || InterlockedCompareExchange (&tp->nthreads, nt - 1, nt) == nt) {
1600 #ifndef DISABLE_PERFCOUNTERS
1601 mono_perfcounter_update_value (tp->pc_nthreads, TRUE, -1);
1607 fire_profiler_thread_end ();
1610 tp_finish_func (tp_hooks_user_data);
1617 g_assert_not_reached ();
1621 ves_icall_System_Threading_ThreadPool_GetAvailableThreads (gint *workerThreads, gint *completionPortThreads)
1623 *workerThreads = async_tp.max_threads - async_tp.busy_threads;
1624 *completionPortThreads = async_io_tp.max_threads - async_io_tp.busy_threads;
1628 ves_icall_System_Threading_ThreadPool_GetMaxThreads (gint *workerThreads, gint *completionPortThreads)
1630 *workerThreads = async_tp.max_threads;
1631 *completionPortThreads = async_io_tp.max_threads;
1635 ves_icall_System_Threading_ThreadPool_GetMinThreads (gint *workerThreads, gint *completionPortThreads)
1637 *workerThreads = async_tp.min_threads;
1638 *completionPortThreads = async_io_tp.min_threads;
1642 ves_icall_System_Threading_ThreadPool_SetMinThreads (gint workerThreads, gint completionPortThreads)
1645 gint max_io_threads;
1647 max_threads = async_tp.max_threads;
1648 if (workerThreads <= 0 || workerThreads > max_threads)
1651 max_io_threads = async_io_tp.max_threads;
1652 if (completionPortThreads <= 0 || completionPortThreads > max_io_threads)
1655 InterlockedExchange (&async_tp.min_threads, workerThreads);
1656 InterlockedExchange (&async_io_tp.min_threads, completionPortThreads);
1657 if (workerThreads > async_tp.nthreads)
1658 mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_tp, TRUE, FALSE, SMALL_STACK);
1659 if (completionPortThreads > async_io_tp.nthreads)
1660 mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_io_tp, TRUE, FALSE, SMALL_STACK);
1665 ves_icall_System_Threading_ThreadPool_SetMaxThreads (gint workerThreads, gint completionPortThreads)
1668 gint min_io_threads;
1671 cpu_count = mono_cpu_count ();
1672 min_threads = async_tp.min_threads;
1673 if (workerThreads < min_threads || workerThreads < cpu_count)
1676 /* We don't really have the concept of completion ports. Do we care here? */
1677 min_io_threads = async_io_tp.min_threads;
1678 if (completionPortThreads < min_io_threads || completionPortThreads < cpu_count)
1681 InterlockedExchange (&async_tp.max_threads, workerThreads);
1682 InterlockedExchange (&async_io_tp.max_threads, completionPortThreads);
1687 * mono_install_threadpool_thread_hooks
1688 * @start_func: the function to be called right after a new threadpool thread is created. Can be NULL.
1689 * @finish_func: the function to be called right before a thredpool thread is exiting. Can be NULL.
1690 * @user_data: argument passed to @start_func and @finish_func.
1692 * @start_fun will be called right after a threadpool thread is created and @finish_func right before a threadpool thread exits.
1693 * The calls will be made from the thread itself.
1696 mono_install_threadpool_thread_hooks (MonoThreadPoolFunc start_func, MonoThreadPoolFunc finish_func, gpointer user_data)
1698 tp_start_func = start_func;
1699 tp_finish_func = finish_func;
1700 tp_hooks_user_data = user_data;
1704 * mono_install_threadpool_item_hooks
1705 * @begin_func: the function to be called before a threadpool work item processing starts.
1706 * @end_func: the function to be called after a threadpool work item is finished.
1707 * @user_data: argument passed to @begin_func and @end_func.
1709 * The calls will be made from the thread itself and from the same AppDomain
1710 * where the work item was executed.
1714 mono_install_threadpool_item_hooks (MonoThreadPoolItemFunc begin_func, MonoThreadPoolItemFunc end_func, gpointer user_data)
1716 tp_item_begin_func = begin_func;
1717 tp_item_end_func = end_func;
1718 tp_item_user_data = user_data;
1722 mono_internal_thread_unhandled_exception (MonoObject* exc)
1724 if (mono_runtime_unhandled_exception_policy_get () == MONO_UNHANDLED_POLICY_CURRENT) {
1728 klass = exc->vtable->klass;
1729 unloaded = is_appdomainunloaded_exception (exc->vtable->domain, klass);
1730 if (!unloaded && klass != mono_defaults.threadabortexception_class) {
1731 mono_unhandled_exception (exc);
1732 if (mono_environment_exitcode_get () == 1)
1735 if (klass == mono_defaults.threadabortexception_class)
1736 mono_thread_internal_reset_abort (mono_thread_internal_current ());
1741 * Suspend creation of new threads.
1744 mono_thread_pool_suspend (void)
1750 * Resume creation of new threads.
1753 mono_thread_pool_resume (void)