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-mlist.h>
23 #include <mono/metadata/mono-perfcounters.h>
24 #include <mono/metadata/socket-io.h>
25 #include <mono/metadata/mono-cq.h>
26 #include <mono/metadata/mono-wsq.h>
27 #include <mono/metadata/mono-ptr-array.h>
28 #include <mono/io-layer/io-layer.h>
29 #include <mono/utils/mono-time.h>
30 #include <mono/utils/mono-proclib.h>
31 #include <mono/utils/mono-semaphore.h>
32 #include <mono/utils/atomic.h>
34 #ifdef HAVE_SYS_TIME_H
37 #include <sys/types.h>
43 #ifdef HAVE_SYS_SOCKET_H
44 #include <sys/socket.h>
46 #include <mono/utils/mono-poll.h>
48 #include <sys/epoll.h>
51 #include <sys/event.h>
55 #ifndef DISABLE_SOCKETS
56 #include "mono/io-layer/socket-wrappers.h"
59 #include "threadpool.h"
61 #define THREAD_WANTS_A_BREAK(t) ((t->state & (ThreadState_StopRequested | \
62 ThreadState_SuspendRequested)) != 0)
64 #define SPIN_TRYLOCK(i) (InterlockedCompareExchange (&(i), 1, 0) == 0)
65 #define SPIN_LOCK(i) do { \
66 if (SPIN_TRYLOCK (i)) \
70 #define SPIN_UNLOCK(i) i = 0
71 #define SMALL_STACK (128 * (sizeof (gpointer) / 4) * 1024)
73 /* DEBUG: prints tp data every 2s */
76 /* mono_thread_pool_init called */
77 static volatile int tp_inited;
86 CRITICAL_SECTION io_lock; /* access to sock_to_state */
87 int inited; // 0 -> not initialized , 1->initializing, 2->initialized, 3->cleaned up
88 MonoGHashTable *sock_to_state;
92 void (*modify) (gpointer p, int fd, int operation, int events, gboolean is_new);
93 void (*wait) (gpointer sock_data);
94 void (*shutdown) (gpointer event_data);
97 static SocketIOData socket_io_data;
99 /* Keep in sync with the System.MonoAsyncCall class which provides GC tracking */
102 MonoMethodMessage *msg;
103 MonoMethod *cb_method;
104 MonoDelegate *cb_target;
112 MonoCQ *queue; /* GC root */
114 volatile gint waiting; /* threads waiting for a work item */
117 volatile gint pool_status; /* 0 -> not initialized, 1 -> initialized, 2 -> cleaning up */
118 /* min, max, n and busy -> Interlocked */
119 volatile gint min_threads;
120 volatile gint max_threads;
121 volatile gint nthreads;
122 volatile gint busy_threads;
124 void (*async_invoke) (gpointer data);
125 void *pc_nitems; /* Performance counter for total number of items in added */
126 void *pc_nthreads; /* Performance counter for total number of active threads */
128 volatile gint destroy_thread;
129 volatile gint ignore_times; /* Used when there's a thread being created or destroyed */
130 volatile gint sp_lock; /* spin lock used to protect ignore_times */
131 volatile gint64 last_check;
132 volatile gint64 time_sum;
138 static ThreadPool async_tp;
139 static ThreadPool async_io_tp;
141 static void async_invoke_thread (gpointer data);
142 static MonoObject *mono_async_invoke (ThreadPool *tp, MonoAsyncResult *ares);
143 static void threadpool_free_queue (ThreadPool *tp);
144 static void threadpool_append_job (ThreadPool *tp, MonoObject *ar);
145 static void threadpool_append_jobs (ThreadPool *tp, MonoObject **jobs, gint njobs);
146 static void threadpool_init (ThreadPool *tp, int min_threads, int max_threads, void (*async_invoke) (gpointer));
147 static void threadpool_start_idle_threads (ThreadPool *tp);
148 static void threadpool_kill_idle_threads (ThreadPool *tp);
149 static gboolean threadpool_start_thread (ThreadPool *tp);
150 static void monitor_thread (gpointer data);
151 static void socket_io_cleanup (SocketIOData *data);
152 static MonoObject *get_io_event (MonoMList **list, gint event);
153 static int get_events_from_list (MonoMList *list);
154 static int get_event_from_state (MonoSocketAsyncResult *state);
155 static void check_for_interruption_critical (void);
157 static MonoClass *async_call_klass;
158 static MonoClass *socket_async_call_klass;
159 static MonoClass *process_async_call_klass;
161 static GPtrArray *wsqs;
162 CRITICAL_SECTION wsqs_lock;
163 static gboolean suspended;
166 static MonoThreadPoolFunc tp_start_func;
167 static MonoThreadPoolFunc tp_finish_func;
168 static gpointer tp_hooks_user_data;
169 static MonoThreadPoolItemFunc tp_item_begin_func;
170 static MonoThreadPoolItemFunc tp_item_end_func;
171 static gpointer tp_item_user_data;
181 AIO_OP_RECV_JUST_CALLBACK,
182 AIO_OP_SEND_JUST_CALLBACK,
186 AIO_OP_ACCEPTRECEIVE,
187 AIO_OP_RECEIVE_BUFFERS,
192 #include <mono/metadata/tpool-poll.c>
194 #include <mono/metadata/tpool-epoll.c>
195 #elif defined(USE_KQUEUE_FOR_THREADPOOL)
196 #include <mono/metadata/tpool-kqueue.c>
199 * Functions to check whenever a class is given system class. We need to cache things in MonoDomain since some of the
200 * assemblies can be unloaded.
204 is_system_type (MonoDomain *domain, MonoClass *klass)
206 if (domain->system_image == NULL)
207 domain->system_image = mono_image_loaded ("System");
209 return klass->image == domain->system_image;
213 is_corlib_type (MonoDomain *domain, MonoClass *klass)
215 return klass->image == mono_defaults.corlib;
219 * Note that we call it is_socket_type() where 'socket' refers to the image
220 * that contains the System.Net.Sockets.Socket type.
223 is_socket_type (MonoDomain *domain, MonoClass *klass)
225 return is_system_type (domain, klass);
228 #define check_type_cached(domain, ASSEMBLY, _class, _namespace, _name, loc) do { \
230 return *loc == _class; \
231 if (is_##ASSEMBLY##_type (domain, _class) && !strcmp (_name, _class->name) && !strcmp (_namespace, _class->name_space)) { \
238 #define check_corlib_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, corlib, _class, _namespace, _name, loc)
240 #define check_socket_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, socket, _class, _namespace, _name, loc)
242 #define check_system_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, system, _class, _namespace, _name, loc)
245 is_corlib_asyncresult (MonoDomain *domain, MonoClass *klass)
247 check_corlib_type_cached (domain, klass, "System.Runtime.Remoting.Messaging", "AsyncResult", &domain->corlib_asyncresult_class);
251 is_socket (MonoDomain *domain, MonoClass *klass)
253 check_socket_type_cached (domain, klass, "System.Net.Sockets", "Socket", &domain->socket_class);
257 is_socketasyncresult (MonoDomain *domain, MonoClass *klass)
259 return (klass->nested_in &&
260 is_socket (domain, klass->nested_in) &&
261 !strcmp (klass->name, "SocketAsyncResult"));
265 is_socketasynccall (MonoDomain *domain, MonoClass *klass)
267 return (klass->nested_in &&
268 is_socket (domain, klass->nested_in) &&
269 !strcmp (klass->name, "SocketAsyncCall"));
273 is_appdomainunloaded_exception (MonoDomain *domain, MonoClass *klass)
275 check_corlib_type_cached (domain, klass, "System", "AppDomainUnloadedException", &domain->ad_unloaded_ex_class);
279 is_sd_process (MonoDomain *domain, MonoClass *klass)
281 check_system_type_cached (domain, klass, "System.Diagnostics", "Process", &domain->process_class);
285 is_sdp_asyncreadhandler (MonoDomain *domain, MonoClass *klass)
288 return (klass->nested_in &&
289 is_sd_process (domain, klass->nested_in) &&
290 !strcmp (klass->name, "AsyncReadHandler"));
294 #ifdef DISABLE_SOCKETS
296 #define socket_io_cleanup(x)
299 get_event_from_state (MonoSocketAsyncResult *state)
301 g_assert_not_reached ();
306 get_events_from_list (MonoMList *list)
314 socket_io_cleanup (SocketIOData *data)
316 EnterCriticalSection (&data->io_lock);
317 if (data->inited != 2) {
318 LeaveCriticalSection (&data->io_lock);
322 data->shutdown (data->event_data);
323 LeaveCriticalSection (&data->io_lock);
327 get_event_from_state (MonoSocketAsyncResult *state)
329 switch (state->operation) {
332 case AIO_OP_RECV_JUST_CALLBACK:
333 case AIO_OP_RECEIVEFROM:
334 case AIO_OP_READPIPE:
335 case AIO_OP_ACCEPTRECEIVE:
336 case AIO_OP_RECEIVE_BUFFERS:
339 case AIO_OP_SEND_JUST_CALLBACK:
342 case AIO_OP_SEND_BUFFERS:
343 case AIO_OP_DISCONNECT:
345 default: /* Should never happen */
346 g_message ("get_event_from_state: unknown value in switch!!!");
352 get_events_from_list (MonoMList *list)
354 MonoSocketAsyncResult *state;
357 while (list && (state = (MonoSocketAsyncResult *)mono_mlist_get_data (list))) {
358 events |= get_event_from_state (state);
359 list = mono_mlist_next (list);
365 #define ICALL_RECV(x) ves_icall_System_Net_Sockets_Socket_Receive_internal (\
366 (SOCKET)(gssize)x->handle, x->buffer, x->offset, x->size,\
367 x->socket_flags, &x->error);
369 #define ICALL_SEND(x) ves_icall_System_Net_Sockets_Socket_Send_internal (\
370 (SOCKET)(gssize)x->handle, x->buffer, x->offset, x->size,\
371 x->socket_flags, &x->error);
373 #endif /* !DISABLE_SOCKETS */
376 threadpool_jobs_inc (MonoObject *obj)
379 InterlockedIncrement (&obj->vtable->domain->threadpool_jobs);
383 threadpool_jobs_dec (MonoObject *obj)
391 domain = obj->vtable->domain;
392 remaining_jobs = InterlockedDecrement (&domain->threadpool_jobs);
393 if (remaining_jobs == 0 && domain->cleanup_semaphore) {
394 ReleaseSemaphore (domain->cleanup_semaphore, 1, NULL);
401 get_io_event (MonoMList **list, gint event)
411 state = mono_mlist_get_data (current);
412 if (get_event_from_state ((MonoSocketAsyncResult *) state) == event)
417 current = mono_mlist_next (current);
422 mono_mlist_set_next (prev, mono_mlist_next (current));
424 *list = mono_mlist_next (*list);
432 * select/poll wake up when a socket is closed, but epoll just removes
433 * the socket from its internal list without notification.
436 mono_thread_pool_remove_socket (int sock)
439 MonoSocketAsyncResult *state;
442 if (socket_io_data.inited == 0)
445 EnterCriticalSection (&socket_io_data.io_lock);
446 if (socket_io_data.sock_to_state == NULL) {
447 LeaveCriticalSection (&socket_io_data.io_lock);
450 list = mono_g_hash_table_lookup (socket_io_data.sock_to_state, GINT_TO_POINTER (sock));
452 mono_g_hash_table_remove (socket_io_data.sock_to_state, GINT_TO_POINTER (sock));
453 LeaveCriticalSection (&socket_io_data.io_lock);
456 state = (MonoSocketAsyncResult *) mono_mlist_get_data (list);
457 if (state->operation == AIO_OP_RECEIVE)
458 state->operation = AIO_OP_RECV_JUST_CALLBACK;
459 else if (state->operation == AIO_OP_SEND)
460 state->operation = AIO_OP_SEND_JUST_CALLBACK;
462 ares = get_io_event (&list, MONO_POLLIN);
463 threadpool_append_job (&async_io_tp, ares);
465 ares = get_io_event (&list, MONO_POLLOUT);
466 threadpool_append_job (&async_io_tp, ares);
472 init_event_system (SocketIOData *data)
475 if (data->event_system == EPOLL_BACKEND) {
476 data->event_data = tp_epoll_init (data);
477 if (data->event_data == NULL) {
478 if (g_getenv ("MONO_DEBUG"))
479 g_message ("Falling back to poll()");
480 data->event_system = POLL_BACKEND;
483 #elif defined(USE_KQUEUE_FOR_THREADPOOL)
484 if (data->event_system == KQUEUE_BACKEND)
485 data->event_data = tp_kqueue_init (data);
487 if (data->event_system == POLL_BACKEND)
488 data->event_data = tp_poll_init (data);
492 socket_io_init (SocketIOData *data)
496 if (data->inited >= 2) // 2 -> initialized, 3-> cleaned up
499 inited = InterlockedCompareExchange (&data->inited, 1, 0);
502 if (data->inited >= 2)
508 EnterCriticalSection (&data->io_lock);
509 data->sock_to_state = mono_g_hash_table_new_type (g_direct_hash, g_direct_equal, MONO_HASH_VALUE_GC);
511 data->event_system = EPOLL_BACKEND;
512 #elif defined(USE_KQUEUE_FOR_THREADPOOL)
513 data->event_system = KQUEUE_BACKEND;
515 data->event_system = POLL_BACKEND;
517 if (g_getenv ("MONO_DISABLE_AIO") != NULL)
518 data->event_system = POLL_BACKEND;
520 init_event_system (data);
521 mono_thread_create_internal (mono_get_root_domain (), data->wait, data, TRUE, FALSE, SMALL_STACK);
522 LeaveCriticalSection (&data->io_lock);
524 threadpool_start_thread (&async_io_tp);
528 socket_io_add (MonoAsyncResult *ares, MonoSocketAsyncResult *state)
531 SocketIOData *data = &socket_io_data;
536 socket_io_init (&socket_io_data);
537 if (mono_runtime_is_shutting_down () || data->inited == 3 || data->sock_to_state == NULL)
539 if (async_tp.pool_status == 2)
542 MONO_OBJECT_SETREF (state, ares, ares);
544 fd = GPOINTER_TO_INT (state->handle);
545 EnterCriticalSection (&data->io_lock);
546 if (data->sock_to_state == NULL) {
547 LeaveCriticalSection (&data->io_lock);
550 list = mono_g_hash_table_lookup (data->sock_to_state, GINT_TO_POINTER (fd));
552 list = mono_mlist_alloc ((MonoObject*)state);
555 list = mono_mlist_append (list, (MonoObject*)state);
559 mono_g_hash_table_replace (data->sock_to_state, state->handle, list);
560 ievt = get_events_from_list (list);
561 /* The modify function leaves the io_lock critical section. */
562 data->modify (data, fd, state->operation, ievt, is_new);
565 #ifndef DISABLE_SOCKETS
567 socket_io_filter (MonoObject *target, MonoObject *state)
570 MonoSocketAsyncResult *sock_res;
574 if (target == NULL || state == NULL)
577 domain = target->vtable->domain;
578 klass = target->vtable->klass;
579 if (socket_async_call_klass == NULL && is_socketasynccall (domain, klass))
580 socket_async_call_klass = klass;
582 if (process_async_call_klass == NULL && is_sdp_asyncreadhandler (domain, klass))
583 process_async_call_klass = klass;
585 if (klass != socket_async_call_klass && klass != process_async_call_klass)
588 sock_res = (MonoSocketAsyncResult *) state;
589 op = sock_res->operation;
590 if (op < AIO_OP_FIRST || op >= AIO_OP_LAST)
595 #endif /* !DISABLE_SOCKETS */
597 /* Returns the exception thrown when invoking, if any */
599 mono_async_invoke (ThreadPool *tp, MonoAsyncResult *ares)
601 ASyncCall *ac = (ASyncCall *)ares->object_data;
602 MonoObject *res, *exc = NULL;
603 MonoArray *out_args = NULL;
604 HANDLE wait_event = NULL;
605 MonoInternalThread *thread = mono_thread_internal_current ();
607 if (ares->execution_context) {
608 /* use captured ExecutionContext (if available) */
609 MONO_OBJECT_SETREF (ares, original_context, mono_thread_get_execution_context ());
610 mono_thread_set_execution_context (ares->execution_context);
612 ares->original_context = NULL;
616 /* Fast path from ThreadPool.*QueueUserWorkItem */
617 void *pa = ares->async_state;
618 /* The debugger needs this */
619 thread->async_invoke_method = ((MonoDelegate*)ares->async_delegate)->method;
620 res = mono_runtime_delegate_invoke (ares->async_delegate, &pa, &exc);
621 thread->async_invoke_method = NULL;
623 MonoObject *cb_exc = NULL;
626 res = mono_message_invoke (ares->async_delegate, ac->msg, &exc, &out_args);
627 MONO_OBJECT_SETREF (ac, res, res);
628 MONO_OBJECT_SETREF (ac, msg->exc, exc);
629 MONO_OBJECT_SETREF (ac, out_args, out_args);
631 mono_monitor_enter ((MonoObject *) ares);
633 if (ares->handle != NULL)
634 wait_event = mono_wait_handle_get_handle ((MonoWaitHandle *) ares->handle);
635 mono_monitor_exit ((MonoObject *) ares);
636 /* notify listeners */
637 if (wait_event != NULL)
638 SetEvent (wait_event);
640 /* call async callback if cb_method != null*/
641 if (ac != NULL && ac->cb_method) {
644 thread->async_invoke_method = ac->cb_method;
645 mono_runtime_invoke (ac->cb_method, ac->cb_target, pa, &cb_exc);
646 thread->async_invoke_method = NULL;
653 /* restore original thread execution context if flow isn't suppressed, i.e. non null */
654 if (ares->original_context) {
655 mono_thread_set_execution_context (ares->original_context);
656 ares->original_context = NULL;
662 threadpool_start_idle_threads (ThreadPool *tp)
667 stack_size = (!tp->is_io) ? 0 : SMALL_STACK;
671 if (n >= tp->min_threads)
673 if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n)
676 #ifndef DISABLE_PERFCOUNTERS
677 mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
679 mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, FALSE, stack_size);
685 threadpool_init (ThreadPool *tp, int min_threads, int max_threads, void (*async_invoke) (gpointer))
687 memset (tp, 0, sizeof (ThreadPool));
688 tp->min_threads = min_threads;
689 tp->max_threads = max_threads;
690 tp->async_invoke = async_invoke;
691 tp->queue = mono_cq_create ();
692 MONO_SEM_INIT (&tp->new_job, 0);
695 #ifndef DISABLE_PERFCOUNTERS
697 init_perf_counter (const char *category, const char *counter)
699 MonoString *category_str;
700 MonoString *counter_str;
706 if (category == NULL || counter == NULL)
708 root = mono_get_root_domain ();
709 category_str = mono_string_new (root, category);
710 counter_str = mono_string_new (root, counter);
711 machine = mono_string_new (root, ".");
712 return mono_perfcounter_get_impl (category_str, counter_str, NULL, machine, &type, &custom);
718 print_pool_info (ThreadPool *tp)
721 // if (tp->tail - tp->head == 0)
724 g_print ("Pool status? %d\n", InterlockedCompareExchange (&tp->pool_status, 0, 0));
725 g_print ("Min. threads: %d\n", InterlockedCompareExchange (&tp->min_threads, 0, 0));
726 g_print ("Max. threads: %d\n", InterlockedCompareExchange (&tp->max_threads, 0, 0));
727 g_print ("nthreads: %d\n", InterlockedCompareExchange (&tp->nthreads, 0, 0));
728 g_print ("busy threads: %d\n", InterlockedCompareExchange (&tp->busy_threads, 0, 0));
729 g_print ("Waiting: %d\n", InterlockedCompareExchange (&tp->waiting, 0, 0));
730 g_print ("Queued: %d\n", (tp->tail - tp->head));
731 if (tp == &async_tp) {
733 EnterCriticalSection (&wsqs_lock);
734 for (i = 0; i < wsqs->len; i++) {
735 g_print ("\tWSQ %d: %d\n", i, mono_wsq_count (g_ptr_array_index (wsqs, i)));
737 LeaveCriticalSection (&wsqs_lock);
739 g_print ("\tSockets: %d\n", mono_g_hash_table_size (socket_io_data.sock_to_state));
741 g_print ("-------------\n");
745 signal_handler (int signo)
750 g_print ("\n-----Non-IO-----\n");
751 print_pool_info (tp);
753 g_print ("\n-----IO-----\n");
754 print_pool_info (tp);
760 monitor_thread (gpointer unused)
762 ThreadPool *pools [2];
763 MonoInternalThread *thread;
768 pools [0] = &async_tp;
769 pools [1] = &async_io_tp;
770 thread = mono_thread_internal_current ();
771 ves_icall_System_Threading_Thread_SetName_internal (thread, mono_string_new (mono_domain_get (), "Threadpool monitor"));
774 i = 10; //number of spurious awakes we tolerate before doing a round of rebalancing.
777 ts = mono_msec_ticks ();
778 if (SleepEx (ms, TRUE) == 0)
780 ms -= (mono_msec_ticks () - ts);
781 if (mono_runtime_is_shutting_down ())
783 if (THREAD_WANTS_A_BREAK (thread))
784 mono_thread_interruption_checkpoint ();
785 } while (ms > 0 && i--);
787 if (mono_runtime_is_shutting_down ())
793 for (i = 0; i < 2; i++) {
798 need_one = (mono_cq_count (tp->queue) > 0);
799 if (!need_one && !tp->is_io) {
800 EnterCriticalSection (&wsqs_lock);
801 for (i = 0; wsqs != NULL && i < wsqs->len; i++) {
803 wsq = g_ptr_array_index (wsqs, i);
804 if (mono_wsq_count (wsq) != 0) {
809 LeaveCriticalSection (&wsqs_lock);
812 threadpool_start_thread (tp);
818 mono_thread_pool_init_tls (void)
824 mono_thread_pool_init (void)
826 gint threads_per_cpu = 1;
828 gint cpu_count = mono_cpu_count ();
834 result = InterlockedCompareExchange (&tp_inited, 1, 0);
843 MONO_GC_REGISTER_ROOT_FIXED (socket_io_data.sock_to_state);
844 InitializeCriticalSection (&socket_io_data.io_lock);
845 if (g_getenv ("MONO_THREADS_PER_CPU") != NULL) {
846 threads_per_cpu = atoi (g_getenv ("MONO_THREADS_PER_CPU"));
847 if (threads_per_cpu < 1)
851 thread_count = MIN (cpu_count * threads_per_cpu, 100 * cpu_count);
852 threadpool_init (&async_tp, thread_count, MAX (100 * cpu_count, thread_count), async_invoke_thread);
853 threadpool_init (&async_io_tp, cpu_count * 2, cpu_count * 4, async_invoke_thread);
854 async_io_tp.is_io = TRUE;
856 async_call_klass = mono_class_from_name (mono_defaults.corlib, "System", "MonoAsyncCall");
857 g_assert (async_call_klass);
859 InitializeCriticalSection (&wsqs_lock);
860 wsqs = g_ptr_array_sized_new (MAX (100 * cpu_count, thread_count));
862 #ifndef DISABLE_PERFCOUNTERS
863 async_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "Work Items Added");
864 g_assert (async_tp.pc_nitems);
866 async_io_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "IO Work Items Added");
867 g_assert (async_io_tp.pc_nitems);
869 async_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of Threads");
870 g_assert (async_tp.pc_nthreads);
872 async_io_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of IO Threads");
873 g_assert (async_io_tp.pc_nthreads);
877 signal (SIGALRM, signal_handler);
882 static MonoAsyncResult *
883 create_simple_asyncresult (MonoObject *target, MonoObject *state)
885 MonoDomain *domain = mono_domain_get ();
886 MonoAsyncResult *ares;
888 /* Don't call mono_async_result_new() to avoid capturing the context */
889 ares = (MonoAsyncResult *) mono_object_new (domain, mono_defaults.asyncresult_class);
890 MONO_OBJECT_SETREF (ares, async_delegate, target);
891 MONO_OBJECT_SETREF (ares, async_state, state);
896 icall_append_io_job (MonoObject *target, MonoSocketAsyncResult *state)
898 MonoAsyncResult *ares;
900 ares = create_simple_asyncresult (target, (MonoObject *) state);
901 socket_io_add (ares, state);
905 mono_thread_pool_add (MonoObject *target, MonoMethodMessage *msg, MonoDelegate *async_callback,
908 MonoDomain *domain = mono_domain_get ();
909 MonoAsyncResult *ares;
912 ac = (ASyncCall*)mono_object_new (domain, async_call_klass);
913 MONO_OBJECT_SETREF (ac, msg, msg);
914 MONO_OBJECT_SETREF (ac, state, state);
916 if (async_callback) {
917 ac->cb_method = mono_get_delegate_invoke (((MonoObject *)async_callback)->vtable->klass);
918 MONO_OBJECT_SETREF (ac, cb_target, async_callback);
921 ares = mono_async_result_new (domain, NULL, ac->state, NULL, (MonoObject*)ac);
922 MONO_OBJECT_SETREF (ares, async_delegate, target);
924 #ifndef DISABLE_SOCKETS
925 if (socket_io_filter (target, state)) {
926 socket_io_add (ares, (MonoSocketAsyncResult *) state);
930 threadpool_append_job (&async_tp, (MonoObject *) ares);
935 mono_thread_pool_finish (MonoAsyncResult *ares, MonoArray **out_args, MonoObject **exc)
943 /* check if already finished */
944 mono_monitor_enter ((MonoObject *) ares);
946 if (ares->endinvoke_called) {
947 *exc = (MonoObject *) mono_get_exception_invalid_operation (NULL);
948 mono_monitor_exit ((MonoObject *) ares);
952 ares->endinvoke_called = 1;
953 /* wait until we are really finished */
954 if (!ares->completed) {
955 if (ares->handle == NULL) {
956 wait_event = CreateEvent (NULL, TRUE, FALSE, NULL);
957 g_assert(wait_event != 0);
958 MONO_OBJECT_SETREF (ares, handle, (MonoObject *) mono_wait_handle_new (mono_object_domain (ares), wait_event));
960 wait_event = mono_wait_handle_get_handle ((MonoWaitHandle *) ares->handle);
962 mono_monitor_exit ((MonoObject *) ares);
963 WaitForSingleObjectEx (wait_event, INFINITE, TRUE);
965 mono_monitor_exit ((MonoObject *) ares);
968 ac = (ASyncCall *) ares->object_data;
969 g_assert (ac != NULL);
970 *exc = ac->msg->exc; /* FIXME: GC add write barrier */
971 *out_args = ac->out_args;
977 threadpool_kill_idle_threads (ThreadPool *tp)
981 n = (gint) InterlockedCompareExchange (&tp->max_threads, 0, -1);
984 MONO_SEM_POST (&tp->new_job);
989 mono_thread_pool_cleanup (void)
991 if (InterlockedExchange (&async_io_tp.pool_status, 2) == 1) {
992 socket_io_cleanup (&socket_io_data); /* Empty when DISABLE_SOCKETS is defined */
993 threadpool_kill_idle_threads (&async_io_tp);
996 if (async_io_tp.queue != NULL) {
997 MONO_SEM_DESTROY (&async_io_tp.new_job);
998 threadpool_free_queue (&async_io_tp);
1002 if (InterlockedExchange (&async_tp.pool_status, 2) == 1) {
1003 threadpool_kill_idle_threads (&async_tp);
1004 threadpool_free_queue (&async_tp);
1008 EnterCriticalSection (&wsqs_lock);
1009 mono_wsq_cleanup ();
1011 g_ptr_array_free (wsqs, TRUE);
1013 LeaveCriticalSection (&wsqs_lock);
1014 MONO_SEM_DESTROY (&async_tp.new_job);
1019 threadpool_start_thread (ThreadPool *tp)
1024 stack_size = (!tp->is_io) ? 0 : SMALL_STACK;
1025 while (!mono_runtime_is_shutting_down () && (n = tp->nthreads) < tp->max_threads) {
1026 if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n) {
1027 #ifndef DISABLE_PERFCOUNTERS
1028 mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
1030 mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, FALSE, stack_size);
1039 pulse_on_new_job (ThreadPool *tp)
1042 MONO_SEM_POST (&tp->new_job);
1046 icall_append_job (MonoObject *ar)
1048 threadpool_append_jobs (&async_tp, &ar, 1);
1052 threadpool_append_job (ThreadPool *tp, MonoObject *ar)
1054 threadpool_append_jobs (tp, &ar, 1);
1058 threadpool_append_jobs (ThreadPool *tp, MonoObject **jobs, gint njobs)
1060 static int job_counter;
1064 if (mono_runtime_is_shutting_down ())
1067 if (tp->pool_status == 0 && InterlockedCompareExchange (&tp->pool_status, 1, 0) == 0) {
1069 mono_thread_create_internal (mono_get_root_domain (), monitor_thread, NULL, TRUE, FALSE, SMALL_STACK);
1070 threadpool_start_thread (tp);
1072 /* Create on demand up to min_threads to avoid startup penalty for apps that don't use
1073 * the threadpool that much
1074 * mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, tp, TRUE, FALSE, SMALL_STACK);
1078 for (i = 0; i < njobs; i++) {
1080 if (ar == NULL || mono_domain_is_unloading (ar->vtable->domain))
1081 continue; /* Might happen when cleaning domain jobs */
1082 if (!tp->is_io && (InterlockedIncrement (&job_counter) % 10) == 0) {
1083 MonoAsyncResult *o = (MonoAsyncResult *) ar;
1084 o->add_time = mono_100ns_ticks ();
1086 threadpool_jobs_inc (ar);
1087 #ifndef DISABLE_PERFCOUNTERS
1088 mono_perfcounter_update_value (tp->pc_nitems, TRUE, 1);
1090 if (!tp->is_io && mono_wsq_local_push (ar))
1093 mono_cq_enqueue (tp->queue, ar);
1096 for (i = 0; tp->waiting > 0 && i < MIN(njobs, tp->max_threads); i++)
1097 pulse_on_new_job (tp);
1101 threadpool_clear_queue (ThreadPool *tp, MonoDomain *domain)
1104 MonoMList *other = NULL;
1105 MonoCQ *queue = tp->queue;
1110 while (mono_cq_dequeue (queue, &obj)) {
1113 if (obj->vtable->domain != domain)
1114 other = mono_mlist_prepend (other, obj);
1115 threadpool_jobs_dec (obj);
1118 if (mono_runtime_is_shutting_down ())
1122 threadpool_append_job (tp, (MonoObject *) mono_mlist_get_data (other));
1123 other = mono_mlist_next (other);
1128 remove_sockstate_for_domain (gpointer key, gpointer value, gpointer user_data)
1130 MonoMList *list = value;
1131 gboolean remove = FALSE;
1133 MonoObject *data = mono_mlist_get_data (list);
1134 if (mono_object_domain (data) == user_data) {
1136 mono_mlist_set_data (list, NULL);
1138 list = mono_mlist_next (list);
1140 //FIXME is there some sort of additional unregistration we need to perform here?
1145 * Clean up the threadpool of all domain jobs.
1146 * Can only be called as part of the domain unloading process as
1147 * it will wait for all jobs to be visible to the interruption code.
1150 mono_thread_pool_remove_domain_jobs (MonoDomain *domain, int timeout)
1154 guint32 start_time = 0;
1156 g_assert (domain->state == MONO_APPDOMAIN_UNLOADING);
1158 threadpool_clear_queue (&async_tp, domain);
1159 threadpool_clear_queue (&async_io_tp, domain);
1161 EnterCriticalSection (&socket_io_data.io_lock);
1162 if (socket_io_data.sock_to_state)
1163 mono_g_hash_table_foreach_remove (socket_io_data.sock_to_state, remove_sockstate_for_domain, domain);
1165 LeaveCriticalSection (&socket_io_data.io_lock);
1168 * There might be some threads out that could be about to execute stuff from the given domain.
1169 * We avoid that by setting up a semaphore to be pulsed by the thread that reaches zero.
1171 sem_handle = CreateSemaphore (NULL, 0, 1, NULL);
1173 domain->cleanup_semaphore = sem_handle;
1175 * The memory barrier here is required to have global ordering between assigning to cleanup_semaphone
1176 * and reading threadpool_jobs.
1177 * Otherwise this thread could read a stale version of threadpool_jobs and wait forever.
1179 mono_memory_write_barrier ();
1181 if (domain->threadpool_jobs && timeout != -1)
1182 start_time = mono_msec_ticks ();
1183 while (domain->threadpool_jobs) {
1184 WaitForSingleObject (sem_handle, timeout);
1185 if (timeout != -1 && (mono_msec_ticks () - start_time) > timeout) {
1191 domain->cleanup_semaphore = NULL;
1192 CloseHandle (sem_handle);
1197 threadpool_free_queue (ThreadPool *tp)
1199 mono_cq_destroy (tp->queue);
1204 mono_thread_pool_is_queue_array (MonoArray *o)
1206 // gpointer obj = o;
1208 // FIXME: need some fix in sgen code.
1218 EnterCriticalSection (&wsqs_lock);
1219 wsq = mono_wsq_create ();
1221 LeaveCriticalSection (&wsqs_lock);
1224 for (i = 0; i < wsqs->len; i++) {
1225 if (g_ptr_array_index (wsqs, i) == NULL) {
1226 wsqs->pdata [i] = wsq;
1227 LeaveCriticalSection (&wsqs_lock);
1231 g_ptr_array_add (wsqs, wsq);
1232 LeaveCriticalSection (&wsqs_lock);
1237 remove_wsq (MonoWSQ *wsq)
1244 EnterCriticalSection (&wsqs_lock);
1246 LeaveCriticalSection (&wsqs_lock);
1249 g_ptr_array_remove_fast (wsqs, wsq);
1252 * Only clean this up when shutting down, any other case will error out
1253 * if we're removing a queue that still has work items.
1255 if (mono_runtime_is_shutting_down ()) {
1256 while (mono_wsq_local_pop (&data)) {
1257 threadpool_jobs_dec (data);
1261 mono_wsq_destroy (wsq);
1262 LeaveCriticalSection (&wsqs_lock);
1266 try_steal (MonoWSQ *local_wsq, gpointer *data, gboolean retry)
1271 if (wsqs == NULL || data == NULL || *data != NULL)
1276 if (mono_runtime_is_shutting_down ())
1279 EnterCriticalSection (&wsqs_lock);
1280 for (i = 0; wsqs != NULL && i < wsqs->len; i++) {
1283 wsq = wsqs->pdata [i];
1284 if (wsq == local_wsq || mono_wsq_count (wsq) == 0)
1286 mono_wsq_try_steal (wsqs->pdata [i], data, ms);
1287 if (*data != NULL) {
1288 LeaveCriticalSection (&wsqs_lock);
1292 LeaveCriticalSection (&wsqs_lock);
1294 } while (retry && ms < 11);
1298 dequeue_or_steal (ThreadPool *tp, gpointer *data, MonoWSQ *local_wsq)
1300 if (mono_runtime_is_shutting_down ())
1302 mono_cq_dequeue (tp->queue, (MonoObject **) data);
1303 if (!tp->is_io && !*data)
1304 try_steal (local_wsq, data, FALSE);
1305 return (*data != NULL);
1309 process_idle_times (ThreadPool *tp, gint64 t)
1313 gboolean compute_avg;
1317 if (tp->ignore_times || t <= 0)
1320 compute_avg = FALSE;
1321 ticks = mono_100ns_ticks ();
1323 SPIN_LOCK (tp->sp_lock);
1324 if (tp->ignore_times) {
1325 SPIN_UNLOCK (tp->sp_lock);
1330 if (tp->last_check == 0)
1331 tp->last_check = ticks;
1332 else if (tp->last_check > 0 && (ticks - tp->last_check) > 5000000) {
1333 tp->ignore_times = 1;
1336 SPIN_UNLOCK (tp->sp_lock);
1341 //printf ("Items: %d Time elapsed: %.3fs\n", tp->n_sum, (ticks - tp->last_check) / 10000.0);
1342 tp->last_check = ticks;
1344 avg = tp->time_sum / tp->n_sum;
1345 if (tp->averages [1] == 0) {
1346 tp->averages [1] = avg;
1348 per1 = ((100 * (ABS (avg - tp->averages [1]))) / tp->averages [1]);
1350 if (avg > tp->averages [1]) {
1351 if (tp->averages [1] < tp->averages [0]) {
1356 } else if (avg < tp->averages [1] && tp->averages [1] < tp->averages [0]) {
1361 min = tp->min_threads;
1363 if ((n - min) < min && tp->busy_threads == n)
1367 if (new_threads != 0) {
1368 printf ("n: %d per1: %lld avg=%lld avg1=%lld avg0=%lld\n", new_threads, per1, avg, tp->averages [1], tp->averages [0]);
1376 tp->averages [0] = tp->averages [1];
1377 tp->averages [1] = avg;
1378 tp->ignore_times = 0;
1380 if (new_threads == -1) {
1381 if (tp->destroy_thread == 0 && InterlockedCompareExchange (&tp->destroy_thread, 1, 0) == 0)
1382 pulse_on_new_job (tp);
1387 should_i_die (ThreadPool *tp)
1389 gboolean result = FALSE;
1390 if (tp->destroy_thread == 1 && InterlockedCompareExchange (&tp->destroy_thread, 0, 1) == 1)
1391 result = (tp->nthreads > tp->min_threads);
1396 set_tp_thread_info (ThreadPool *tp)
1399 MonoInternalThread *thread = mono_thread_internal_current ();
1401 mono_profiler_thread_start (thread->tid);
1402 name = (tp->is_io) ? "IO Threadpool worker" : "Threadpool worker";
1403 mono_thread_set_name_internal (thread, mono_string_new (mono_domain_get (), name), FALSE);
1407 clear_thread_state (void)
1409 MonoInternalThread *thread = mono_thread_internal_current ();
1410 /* If the callee changes the background status, set it back to TRUE */
1411 mono_thread_clr_state (thread , ~ThreadState_Background);
1412 if (!mono_thread_test_state (thread , ThreadState_Background))
1413 ves_icall_System_Threading_Thread_SetState (thread, ThreadState_Background);
1417 check_for_interruption_critical (void)
1419 MonoInternalThread *thread;
1420 /*RULE NUMBER ONE OF SKIP_THREAD: NEVER POKE MANAGED STATE.*/
1421 mono_gc_set_skip_thread (FALSE);
1423 thread = mono_thread_internal_current ();
1424 if (THREAD_WANTS_A_BREAK (thread))
1425 mono_thread_interruption_checkpoint ();
1427 /*RULE NUMBER TWO OF SKIP_THREAD: READ RULE NUMBER ONE.*/
1428 mono_gc_set_skip_thread (TRUE);
1432 fire_profiler_thread_end (void)
1434 MonoInternalThread *thread = mono_thread_internal_current ();
1435 mono_profiler_thread_end (thread->tid);
1439 async_invoke_thread (gpointer data)
1451 set_tp_thread_info (tp);
1454 tp_start_func (tp_hooks_user_data);
1458 MonoAsyncResult *ar;
1460 gboolean is_io_task;
1465 ar = (MonoAsyncResult *) data;
1467 InterlockedIncrement (&tp->busy_threads);
1468 domain = ((MonoObject *)ar)->vtable->domain;
1469 #ifndef DISABLE_SOCKETS
1470 klass = ((MonoObject *) data)->vtable->klass;
1471 is_io_task = !is_corlib_asyncresult (domain, klass);
1474 MonoSocketAsyncResult *state = (MonoSocketAsyncResult *) data;
1475 is_socket = is_socketasyncresult (domain, klass);
1477 switch (state->operation) {
1478 case AIO_OP_RECEIVE:
1479 state->total = ICALL_RECV (state);
1482 state->total = ICALL_SEND (state);
1487 /* worker threads invokes methods in different domains,
1488 * so we need to set the right domain here */
1491 if (mono_domain_is_unloading (domain) || mono_runtime_is_shutting_down ()) {
1492 threadpool_jobs_dec ((MonoObject *)ar);
1495 InterlockedDecrement (&tp->busy_threads);
1497 mono_thread_push_appdomain_ref (domain);
1498 if (threadpool_jobs_dec ((MonoObject *)ar)) {
1501 mono_thread_pop_appdomain_ref ();
1502 InterlockedDecrement (&tp->busy_threads);
1506 if (mono_domain_set (domain, FALSE)) {
1509 if (tp_item_begin_func)
1510 tp_item_begin_func (tp_item_user_data);
1512 if (!is_io_task && ar->add_time > 0)
1513 process_idle_times (tp, ar->add_time);
1514 exc = mono_async_invoke (tp, ar);
1515 if (tp_item_end_func)
1516 tp_item_end_func (tp_item_user_data);
1518 mono_internal_thread_unhandled_exception (exc);
1519 if (is_socket && tp->is_io) {
1520 MonoSocketAsyncResult *state = (MonoSocketAsyncResult *) data;
1522 if (state->completed && state->callback) {
1523 MonoAsyncResult *cb_ares;
1524 cb_ares = create_simple_asyncresult ((MonoObject *) state->callback,
1525 (MonoObject *) state);
1526 icall_append_job ((MonoObject *) cb_ares);
1529 mono_domain_set (mono_get_root_domain (), TRUE);
1531 mono_thread_pop_appdomain_ref ();
1532 InterlockedDecrement (&tp->busy_threads);
1533 clear_thread_state ();
1539 must_die = should_i_die (tp);
1540 if (!must_die && (tp->is_io || !mono_wsq_local_pop (&data)))
1541 dequeue_or_steal (tp, &data, wsq);
1544 while (!must_die && !data && n_naps < 4) {
1547 InterlockedIncrement (&tp->waiting);
1549 // Another thread may have added a job into its wsq since the last call to dequeue_or_steal
1550 // Check all the queues again before entering the wait loop
1551 dequeue_or_steal (tp, &data, wsq);
1553 InterlockedDecrement (&tp->waiting);
1557 mono_gc_set_skip_thread (TRUE);
1559 #if defined(__OpenBSD__)
1560 while (mono_cq_count (tp->queue) == 0 && (res = mono_sem_wait (&tp->new_job, TRUE)) == -1) {// && errno == EINTR) {
1562 while (mono_cq_count (tp->queue) == 0 && (res = mono_sem_timedwait (&tp->new_job, 2000, TRUE)) == -1) {// && errno == EINTR) {
1564 if (mono_runtime_is_shutting_down ())
1566 check_for_interruption_critical ();
1568 InterlockedDecrement (&tp->waiting);
1570 mono_gc_set_skip_thread (FALSE);
1572 if (mono_runtime_is_shutting_down ())
1574 must_die = should_i_die (tp);
1575 dequeue_or_steal (tp, &data, wsq);
1579 if (!data && !tp->is_io && !mono_runtime_is_shutting_down ()) {
1580 mono_wsq_local_pop (&data);
1581 if (data && must_die) {
1582 InterlockedCompareExchange (&tp->destroy_thread, 1, 0);
1583 pulse_on_new_job (tp);
1592 down = mono_runtime_is_shutting_down ();
1593 if (!down && nt <= tp->min_threads)
1595 if (down || InterlockedCompareExchange (&tp->nthreads, nt - 1, nt) == nt) {
1596 #ifndef DISABLE_PERFCOUNTERS
1597 mono_perfcounter_update_value (tp->pc_nthreads, TRUE, -1);
1603 fire_profiler_thread_end ();
1606 tp_finish_func (tp_hooks_user_data);
1613 g_assert_not_reached ();
1617 ves_icall_System_Threading_ThreadPool_GetAvailableThreads (gint *workerThreads, gint *completionPortThreads)
1619 *workerThreads = async_tp.max_threads - async_tp.busy_threads;
1620 *completionPortThreads = async_io_tp.max_threads - async_io_tp.busy_threads;
1624 ves_icall_System_Threading_ThreadPool_GetMaxThreads (gint *workerThreads, gint *completionPortThreads)
1626 *workerThreads = async_tp.max_threads;
1627 *completionPortThreads = async_io_tp.max_threads;
1631 ves_icall_System_Threading_ThreadPool_GetMinThreads (gint *workerThreads, gint *completionPortThreads)
1633 *workerThreads = async_tp.min_threads;
1634 *completionPortThreads = async_io_tp.min_threads;
1638 ves_icall_System_Threading_ThreadPool_SetMinThreads (gint workerThreads, gint completionPortThreads)
1641 gint max_io_threads;
1643 max_threads = async_tp.max_threads;
1644 if (workerThreads <= 0 || workerThreads > max_threads)
1647 max_io_threads = async_io_tp.max_threads;
1648 if (completionPortThreads <= 0 || completionPortThreads > max_io_threads)
1651 InterlockedExchange (&async_tp.min_threads, workerThreads);
1652 InterlockedExchange (&async_io_tp.min_threads, completionPortThreads);
1653 if (workerThreads > async_tp.nthreads)
1654 mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_tp, TRUE, FALSE, SMALL_STACK);
1655 if (completionPortThreads > async_io_tp.nthreads)
1656 mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_io_tp, TRUE, FALSE, SMALL_STACK);
1661 ves_icall_System_Threading_ThreadPool_SetMaxThreads (gint workerThreads, gint completionPortThreads)
1664 gint min_io_threads;
1667 cpu_count = mono_cpu_count ();
1668 min_threads = async_tp.min_threads;
1669 if (workerThreads < min_threads || workerThreads < cpu_count)
1672 /* We don't really have the concept of completion ports. Do we care here? */
1673 min_io_threads = async_io_tp.min_threads;
1674 if (completionPortThreads < min_io_threads || completionPortThreads < cpu_count)
1677 InterlockedExchange (&async_tp.max_threads, workerThreads);
1678 InterlockedExchange (&async_io_tp.max_threads, completionPortThreads);
1683 * mono_install_threadpool_thread_hooks
1684 * @start_func: the function to be called right after a new threadpool thread is created. Can be NULL.
1685 * @finish_func: the function to be called right before a thredpool thread is exiting. Can be NULL.
1686 * @user_data: argument passed to @start_func and @finish_func.
1688 * @start_fun will be called right after a threadpool thread is created and @finish_func right before a threadpool thread exits.
1689 * The calls will be made from the thread itself.
1692 mono_install_threadpool_thread_hooks (MonoThreadPoolFunc start_func, MonoThreadPoolFunc finish_func, gpointer user_data)
1694 tp_start_func = start_func;
1695 tp_finish_func = finish_func;
1696 tp_hooks_user_data = user_data;
1700 * mono_install_threadpool_item_hooks
1701 * @begin_func: the function to be called before a threadpool work item processing starts.
1702 * @end_func: the function to be called after a threadpool work item is finished.
1703 * @user_data: argument passed to @begin_func and @end_func.
1705 * The calls will be made from the thread itself and from the same AppDomain
1706 * where the work item was executed.
1710 mono_install_threadpool_item_hooks (MonoThreadPoolItemFunc begin_func, MonoThreadPoolItemFunc end_func, gpointer user_data)
1712 tp_item_begin_func = begin_func;
1713 tp_item_end_func = end_func;
1714 tp_item_user_data = user_data;
1718 mono_internal_thread_unhandled_exception (MonoObject* exc)
1720 if (mono_runtime_unhandled_exception_policy_get () == MONO_UNHANDLED_POLICY_CURRENT) {
1724 klass = exc->vtable->klass;
1725 unloaded = is_appdomainunloaded_exception (exc->vtable->domain, klass);
1726 if (!unloaded && klass != mono_defaults.threadabortexception_class) {
1727 mono_unhandled_exception (exc);
1728 if (mono_environment_exitcode_get () == 1)
1731 if (klass == mono_defaults.threadabortexception_class)
1732 mono_thread_internal_reset_abort (mono_thread_internal_current ());
1737 * Suspend creation of new threads.
1740 mono_thread_pool_suspend (void)
1746 * Resume creation of new threads.
1749 mono_thread_pool_resume (void)