C# Ubuntu线程中的Mono崩溃

C# Ubuntu线程中的Mono崩溃,c#,mono,ubuntu-16.04,C#,Mono,Ubuntu 16.04,我的程序(如下)在Fedora22上运行,或者如果我直接从main()调用线程函数。但是如果我在Ubuntu 16.04的线程中启动mono调用,它会这样断言。我做错什么了吗 霍华德·鲁宾 输出: $ rm monotest.dll ; make ; ./monotest Mono C# compiler version 4.8.0.0 mcs monotest.cs /out:monotest.dll /target:library g++ (Ubuntu 5.4.0-6ubuntu1~

我的程序(如下)在Fedora22上运行,或者如果我直接从main()调用线程函数。但是如果我在Ubuntu 16.04的线程中启动mono调用,它会这样断言。我做错什么了吗

霍华德·鲁宾

输出:

$ rm monotest.dll ; make ; ./monotest 
Mono C# compiler version 4.8.0.0 
mcs monotest.cs /out:monotest.dll /target:library 
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(); 
}
//////////////////////// 
// monotest.cs 
namespace MyNamespace  { 

    public class MyClass { 
        public MyClass() { } 

        public void MySum(int arg1, int arg2) { 
            System.Console.WriteLine("MySum(" + arg1 + "," + arg2 + ") => " + (arg1 + arg2)); 
        } 
    } 
} 
################### 
# Makefile 
monotest : monotest.cpp monotest.dll Makefile 
        @g++ --version | head -1 
        g++ $< -o $@ -g3 -std=c++11 `pkg-config --cflags --libs mono-2` 

monotest.dll : monotest.cs 
        @mcs --version 
        mcs $< /out:$@ /target:library 
==================================

// 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(); 
}
//////////////////////// 
// monotest.cs 
namespace MyNamespace  { 

    public class MyClass { 
        public MyClass() { } 

        public void MySum(int arg1, int arg2) { 
            System.Console.WriteLine("MySum(" + arg1 + "," + arg2 + ") => " + (arg1 + arg2)); 
        } 
    } 
} 
################### 
# Makefile 
monotest : monotest.cpp monotest.dll Makefile 
        @g++ --version | head -1 
        g++ $< -o $@ -g3 -std=c++11 `pkg-config --cflags --libs mono-2` 

monotest.dll : monotest.cs 
        @mcs --version 
        mcs $< /out:$@ /target:library 
###############
#生成文件
monotest:monotest.cpp monotest.dll生成文件
@g++--版本| head-1
g++$<-o$@-g3-std=c++11`pkg配置--cflags--libs mono-2`
monotest.dll:monotest.cs
@mcs——版本
mcs$
在mono中使用线程的文档远远不够,但通过实验,线程可以正常工作

一种方法是使用mono_thread_create()

另一种方法是使用mono_jit_init()打开线程外部的域,然后在创建的线程中,在开始时调用mono_thead_attach(),在结束时调用mono_thread_detach()