Unix systems and native API calls on Windows, falling back to the
managed implementation on error.
.TP
+.I "MONO_THREADS_PER_CPU"
+Sets the maximum number of threads in the threadpool per CPU. The default is
+50 for non-windows systems and 25 for windows.
+.TP
.I "MONO_TRACE"
If set, enables the System.Diagnostics.DefaultTraceListener, which will
print the output of the System.Diagnostics Trace and Debug classes.
+2004-10-29 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * appdomain.c: call mono_thread_pool_init.
+ * threadpool.[ch]: new mono_thread_pool_init that sets the max. number
+ of worker threads based on the number of CPUs and the environment
+ variable MONO_THREADS_PER_CPU if present. The defaults are 50 (25)
+ for non-windows (windows) systems.
+
2004-10-27 Chris Toshok <toshok@ximian.com>
* mono-debug-debugger.c (write_class): don't call mono_class_init
#ifdef PLATFORM_WIN32
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
+#define THREADS_PER_CPU 25
+#else
+#define THREADS_PER_CPU 50
#endif
#include <mono/metadata/domain-internals.h>
#include "threadpool.h"
/* maximum number of worker threads */
-int mono_max_worker_threads = 25; /* per available CPU? */
+int mono_max_worker_threads = THREADS_PER_CPU;
static int mono_min_worker_threads = 0;
/* current number of worker threads */
/* current number of busy threads */
static int busy_worker_threads = 0;
+/* mono_thread_pool_init called */
+static int tp_inited;
+
/* we use this to store a reference to the AsyncResult to avoid GC */
static MonoGHashTable *ares_htable = NULL;
LeaveCriticalSection (&ares_lock);
}
+void
+mono_thread_pool_init ()
+{
+ SYSTEM_INFO info;
+ int threads_per_cpu = THREADS_PER_CPU;
+
+ if ((int) InterlockedCompareExchange (&tp_inited, 1, 0) == 1)
+ return;
+
+ MONO_GC_REGISTER_ROOT (ares_htable);
+ InitializeCriticalSection (&ares_lock);
+ ares_htable = mono_g_hash_table_new (NULL, NULL);
+ job_added = CreateSemaphore (NULL, 0, 0x7fffffff, NULL);
+ GetSystemInfo (&info);
+ if (getenv ("MONO_THREADS_PER_CPU") != NULL) {
+ threads_per_cpu = atoi (getenv ("MONO_THREADS_PER_CPU"));
+ if (threads_per_cpu <= 0)
+ threads_per_cpu = THREADS_PER_CPU;
+ }
+
+ mono_max_worker_threads = threads_per_cpu * info.dwNumberOfProcessors;
+}
MonoAsyncResult *
mono_thread_pool_add (MonoObject *target, MonoMethodMessage *msg, MonoDelegate *async_callback,
ares = mono_async_result_new (domain, NULL, ac->state, ac);
ares->async_delegate = target;
- if (!ares_htable) {
- MONO_GC_REGISTER_ROOT (ares_htable);
- InitializeCriticalSection (&ares_lock);
- ares_htable = mono_g_hash_table_new (NULL, NULL);
- job_added = CreateSemaphore (NULL, 0, 0x7fffffff, NULL);
- }
-
EnterCriticalSection (&ares_lock);
mono_g_hash_table_insert (ares_htable, ares, ares);
LeaveCriticalSection (&ares_lock);