Mono 在 Ubuntu 线程中崩溃



我的程序(下图(可以在 Fedora 22 上运行,或者如果我直接从 main(( 调用线程函数。但是如果我在 Ubuntu 16.04 上的线程中启动单声道调用,它会像这样断言。我做错了什么吗?

霍华德·鲁宾

输出:

$ 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 

在 mono 中使用线程的文档非常不足,但通过实验可以使线程工作。

一种方法是使用 mono_thread_create((。

另一种方法是使用 mono_jit_init(( 打开线程外部的域,然后在创建的线程中调用 mono_thead_attach(( 在开头调用,在末尾调用 mono_thread_detach((。

最新更新