Bug 55226 - mono 4.8.1 fails assert
Summary: mono 4.8.1 fails assert
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: 4.8.0 (C9)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-04-14 16:32 UTC by howard.rubin
Modified: 2017-04-18 15:16 UTC (History)
2 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 howard.rubin 2017-04-14 16:32:25 UTC
I'm using mono to call C# from C++ on Ubuntu Linux 16.04. (Also fails on Fedora 25) This works if I initialize mono directly. But when I initialize mono in a thread, the program crashes with a failed assert. Mono was installed according to http://www.mono-project.com/docs/getting-started/install/linux/

$ rm monotest ; make && ./monotest
Mono C# compiler version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
g++ monotest.cpp -o monotest -g3 -std=c++11 `pkg-config --cflags --libs mono-2`
* Assertion at mono-threads-posix.c:265, condition `info->handle' not met

Aborted (core dumped)

// monotest.cpp
#include <thread>
#include <mono/jit/jit.h>

void MonoInitialize() {
    MonoDomain* domain = mono_jit_init("monotest.dll");

int main(int argc, char* argv[]) {
    if (argc == 2) {
    } else {
        std::thread t(MonoInitialize);

# Makefile
monotest : monotest.cpp Makefile
	@mcs --version
	@g++ --version | head -1
	g++ $< -o $@ -g3 -std=c++11 `pkg-config --cflags --libs mono-2`
Comment 1 howard.rubin 2017-04-18 15:16:20 UTC
The documentation for using threads in mono is woefully inadequate, but with experimentation threads can be made to work.

One way is to use mono_thread_create().

Another is to open the domain outside the threads with mono_jit_init(), then in the created threads call mono_thead_attach() at the beginning and mono_thread_detach() at the end.