Bug 49166 - * Assertion at threadpool-ms.c:813, condition `threadpool' not met
Summary: * Assertion at threadpool-ms.c:813, condition `threadpool' not met
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-12-07 01:25 UTC by Zoltan Varga
Modified: 2017-10-06 23:31 UTC (History)
3 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Zoltan Varga 2016-12-07 01:25:30 UTC
This can be reproduced by the following testcase:
using System;
using System.Reflection;
using System.Threading;

public class Tests
	public static void Main (String[] args) {
		Timer t = new Timer (delegate (object state) {}, null, 10000, 1);

Applying the following patch makes it happen more often:
diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c
index 6721ba5..3c8d5ce 100644
--- a/mono/metadata/threads.c
+++ b/mono/metadata/threads.c
@@ -854,6 +854,7 @@ static guint32 WINAPI start_wrapper_internal(StartInfo *start_info, gsize *stack
                g_assert (start_delegate != NULL);
+               mono_thread_info_sleep (3, NULL);
                /* we may want to handle the exception here. See comment below on unhandled exceptions */
                args [0] = (gpointer) start_delegate_arg;
                mono_runtime_delegate_invoke_checked (start_delegate, args, &error);

What seems to happen is that ThreadPool.EnsureVMInitialized() is called by one thread, which calls 
	mono_lazy_initialize (&status, initialize);
but that silently fails because the main thread has called mono_threadpool_ms_cleanup (). So the threadpool is not really initialized, leading to the assertion.

Note You need to log in before you can comment on or make changes to this bug.