我的程序(下面)可以在Fedora 22上运行,或者直接从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 发布于 2017-04-18 23:17:10
关于在mono中使用线程的文档严重不足,但通过实验可以使线程工作。
一种方法是使用mono_thread_create()。
另一种方法是在线程外部使用mono_jit_init()打开域,然后在创建的线程中,在开始时调用mono_thead_attach(),在结束时调用mono_thread_detach()。
https://stackoverflow.com/questions/43376696
复制相似问题