locked
Mono crashes in Ubuntu thread RRS feed

  • Question

  • I'm using mono (now owned by Microsoft) to get from C++ to a C# output interface. This works fine on Fedora, or even on Ubuntu if I initialize mono directly. But when I initialize mono in a thread, the program crashes with a failed assert. What can I do to overcome this?

    - Howard Rubin

    What I tried: I posted to the mono forum, and to stack overflow:

    http://mono.1490590.n4.nabble.com/Mono-in-Ubuntu-thread-td4670463.html#a4670473

    http://stackoverflow.com/questions/43376696/mono-crashes-in-ubuntu-thread

    $ rm monotest ; make ; ./monotest
    Mono C# compiler version 4.8.0.0
    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 Thread() {
        MonoDomain* domain = mono_jit_init("monotest.dll");
        mono_jit_cleanup(domain);
    }
    
    int main() {
        //Thread();
        std::thread t(Thread);
        t.join();
    }
    
    # Makefile
    monotest : monotest.cpp 	Makefile
    	@mcs --version
    	@g++ --version | head -1
    	g++ $< -o $@ -g3 -std=c++11 `pkg-config --cflags --libs mono-2`

    • Edited by Howard Rubin Thursday, April 13, 2017 6:15 PM
    • Moved by CoolDadTx Tuesday, April 18, 2017 1:53 PM Third party product
    Thursday, April 13, 2017 6:09 PM

Answers

  • 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.

    • Marked as answer by Howard Rubin Tuesday, April 18, 2017 3:19 PM
    Tuesday, April 18, 2017 3:19 PM

All replies

  • Hi Howard Rubin,

    Thank you for posting here.

    For your question, it is more related to third party product. We provide support for Microsoft products.

    Thanks for your understanding and cooperation.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 14, 2017 2:34 AM
  • Hi Wendy,

    Thanks for the quick reply. You may not have heard, but Microsoft owns Xamarin. See https://en.wikipedia.org/wiki/Xamarin

    Howard Rubin

    Friday, April 14, 2017 2:34 PM
  • The MSDN forums does not provide support for Mono or Xamarin. Please post your questions in their forums instead.
    Tuesday, April 18, 2017 1:53 PM
  • As I said in my original question, I did post in their forum and got no response.

    Tuesday, April 18, 2017 3:19 PM
  • 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.

    • Marked as answer by Howard Rubin Tuesday, April 18, 2017 3:19 PM
    Tuesday, April 18, 2017 3:19 PM