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 ()
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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

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.