From 9fe9c1338f62e8d347cc278f9f70bd696f7191dc Mon Sep 17 00:00:00 2001 From: Ben Maurer Date: Sat, 2 Oct 2004 23:51:07 +0000 Subject: [PATCH] 2004-10-02 Ben Maurer * threadpool.c: the ares hashtable needs a critical section around it. this prevents some nasty segfaults svn path=/trunk/mono/; revision=34622 --- mono/metadata/ChangeLog | 5 +++++ mono/metadata/threadpool.c | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog index eca131b43c3..aa7c7037949 100644 --- a/mono/metadata/ChangeLog +++ b/mono/metadata/ChangeLog @@ -1,3 +1,8 @@ +2004-10-02 Ben Maurer + + * threadpool.c: the ares hashtable needs a critical section around it. + this prevents some nasty segfaults + 2004-10-02 Massimiliano Mantione * process.c: Fixed alignments to 32 bits as casting to unsigned is unsafe diff --git a/mono/metadata/threadpool.c b/mono/metadata/threadpool.c index d0f6ec67f9a..9a0548480c8 100644 --- a/mono/metadata/threadpool.c +++ b/mono/metadata/threadpool.c @@ -43,6 +43,8 @@ static int busy_worker_threads = 0; /* we use this to store a reference to the AsyncResult to avoid GC */ static MonoGHashTable *ares_htable = NULL; +static CRITICAL_SECTION ares_lock; + /* we append a job */ static HANDLE job_added; @@ -90,9 +92,12 @@ mono_async_invoke (MonoAsyncResult *ares) } mono_monitor_exit ((MonoObject *) ares); + EnterCriticalSection (&ares_lock); mono_g_hash_table_remove (ares_htable, ares); + LeaveCriticalSection (&ares_lock); } + MonoAsyncResult * mono_thread_pool_add (MonoObject *target, MonoMethodMessage *msg, MonoDelegate *async_callback, MonoObject *state) @@ -122,12 +127,15 @@ mono_thread_pool_add (MonoObject *target, MonoMethodMessage *msg, MonoDelegate * 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); + busy = (int) InterlockedCompareExchange (&busy_worker_threads, 0, -1); worker = (int) InterlockedCompareExchange (&mono_worker_threads, 0, -1); if (worker <= ++busy && -- 2.11.4.GIT