我正在尝试使用mono在C#中开发一个微线程消息传递库。从Mono2.4左右开始,显然在“Mono.Tasklets”下已经有了延续(而不是been )。但是,这些工具缺乏我能找到的任何文档,虽然我通常使用它们是有效的,但我偶尔会遇到调试器无法附加的崩溃(但可重现)。
我的具体问题是:
谁知道Mark()函数是什么,以及我需要在哪里/何时调用它?这似乎是一次性的初始化,但我不知道为什么它不会在构造函数中。
使用多个延续有限制吗?我发现你不能将延续传递给另一个线程,但似乎我可以存储多个延续并来回切换?
发布于 2010-07-24 20:13:27
LE:关于崩溃问题,请看这些开放的bug:Bug 566324,Bug 580791,Bug 602502
我自己对此还是个新手,我在这里介绍我到目前为止收集的信息。也许这将是有用的。
1) Mono.Tasklets库(由Miguel de Icaza [READ:here]描述)是一个延续库,可用于构建各种形式的延展系统和轻量级(LW)线程。
一种简单的描述方式是C的Mono can /setjmp的单版本,它们只能用来展开堆栈。
这个库最初是由一个家伙[READ:here]开发的,现在它包含在Mono和文档记录的READ: [here](http://www.mono-project.com/Continuations)中
这家伙在这个抽象之上实现了一个微线程库。现在已经将其移植到Mono.Tasklets框架中
2)延续是一个对象,可以用来存储当前的执行状态,然后可以用来在以后恢复存储的状态。
这里的“执行状态”指的是堆栈,包括调用堆栈和局部变量,以及处理器的寄存器。
当存储的状态被恢复时,程序执行看起来像是跳回到保存状态的位置,所有的局部变量都恢复了。
Wikipedia/Continuations上的An example in C.和更多信息
3)接口为:
public class Continuation {
public Continuation ();
public void Mark ();
public int Store (int state);
public void Restore (int state);
}延续可用于实现microthreads.你可以在Github [READ:here]上查看来自Mono.MicroThreads的代码。
public Continuation()
{
m_handle = alloc_continuation();
Print("Continuation()");
}
public void Mark()
{
Print("Mark()");
// skip 1 frame, ie. this function
mark_continuation_frame(m_handle, 1);
}
public int Store(int data)
{
Print("Store({0})", data);
int res = store_continuation(m_handle, data);
Print("Store({0}) = {1}", data, res);
return res;
}
public void Restore(int data)
{
Print("Restore({0})", data);
restore_continuation(m_handle, data);
Print("Restore() exit (NEVER REACHED)");
}根据所显示的内容,here
mark ()它用于标记要存储的最上面的帧
continuation ( x )将当前状态存储到,并返回给定的整数x。
Store Restore ( y )Store(Y)还原存储的状态,并返回给定的整数y。(请注意,给Restore的整数y实际上是从()方法返回的,因为这是我们在还原状态后所处的位置。)
static void Main()
{
Continuation c = new Continuation();
c.Mark();
int foo = 123;
int val = c.Store(0);
Console.WriteLine("{0} {1}", val, foo);
foo = 321;
if (val < 5)
c.Restore(val + 1);
}当您调用Store()时,将记录当前的执行状态,并且可以通过调用Restore()返回到此状态。
Store()的调用者根据store的结果判断它是初始存储还是还原点:
var c = new Continuation ();
...
switch (c.Store (0)){
case 0:
// First invocation
case 1:
// Restored from the point ahead.
}
...
// Jump back to the switch statement.
c.Restore (1); https://stackoverflow.com/questions/3251322
复制相似问题