vibe.d:尝试向已停止的任务发送消息
当向停止的vibe.d任务发送消息时,应用程序会出现分段错误。我不希望消息被传递,但希望得到关于发送尝试失败的通知(或者至少不会崩溃) 下面的示例说明了此问题vibe.d:尝试向已停止的任务发送消息,d,phobos,vibed,D,Phobos,Vibed,当向停止的vibe.d任务发送消息时,应用程序会出现分段错误。我不希望消息被传递,但希望得到关于发送尝试失败的通知(或者至少不会崩溃) 下面的示例说明了此问题 import std.stdio; import core.thread; import vibe.core.core; import vibe.core.concurrency; static this() { Task t = runTask({ writeln("Hi"); }); t.jo
import std.stdio;
import core.thread;
import vibe.core.core;
import vibe.core.concurrency;
static this() {
Task t = runTask({
writeln("Hi");
});
t.join;
t.send(42);
writeln("Bye");
}
运行上述代码时,输出为:
Hi
Program exited with code -11
。。。而不是:
Hi
Bye
调用堆栈如下所示
#0 0x00007ffff6dbd346 in std.concurrency.MessageBox.put(ref std.concurrency.Message) ()
from /usr/lib64/libphobos2.so.0.71
#1 0x000000000051b0b3 in std.concurrency._send!(int)._send(std.concurrency.MsgType, std.concurrency.Tid, int) (_param_2=42, tid=..., type=<incomplete type>)
at /opt/dmd-2.071/import/std/concurrency.d:640
#2 0x000000000051b06d in std.concurrency._send!(int)._send(std.concurrency.Tid, int) (
_param_1=42, tid=...) at /opt/dmd-2.071/import/std/concurrency.d:629
#3 0x000000000051b04b in std.concurrency.send!(int).send(std.concurrency.Tid, int) (
_param_1=42, tid=...) at /opt/dmd-2.071/import/std/concurrency.d:605
#4 0x000000000051b027 in vibe.core.concurrency.send!(int).send(vibe.core.task.Task, int) (
_param_1=42, task=...)
at /home/user/.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/concurrency.d:1239
#5 0x0000000000517b6b in app._staticCtor1() () at /tmp/test/source/app.d:11
...
std.concurrency.MessageBox.put(参考std.concurrency.Message)()中的0 0x00007ffff6dbd346
from/usr/lib64/libphobos2.so.0.71
#标准并发中的1 0x000000000051b0b3。\u发送!(int)。_send(std.concurrency.MsgType,std.concurrency.Tid,int)(_param_2=42,Tid=…,type=)
at/opt/dmd-2.071/import/std/concurrency.d:640
#标准并发中的2 0x000000000051b06d。\u发送!(int)。_发送(std.concurrency.Tid,int)(
_param_1=42,tid=…)位于/opt/dmd-2.071/import/std/concurrency.d:629
#std.concurrency.send中的3 0x000000000051b04b!发送(std.concurrency.Tid,int)(
_param_1=42,tid=…)位于/opt/dmd-2.071/import/std/concurrency.d:605
#vibe.core.concurrency.send中的4 0x000000000051b027!发送(vibe.core.task.task,int)(
_参数1=42,任务=…)
at/home/user/.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/concurrency.d:1239
#5 0x0000000000517b6b位于/tmp/test/source/app.d:11的应用程序中
...
- 如何防止SEG故障?是否有检查发送功能?这是如何在vibe.d或phobos2中修补的
- 这是vibe.d还是phobos2的bug?
任务
有一个可以使用的运行
属性。我相信这是预期的行为,因为错误处理通常应该在应用程序级别,而不是库级别
import std.stdio;
import core.thread;
import vibe.core.core;
import vibe.core.concurrency;
static this() {
Task t = runTask({
writeln("Hi");
});
t.join;
if (t.running) {
t.send(42);
}
writeln("Bye");
}
当我只有
任务的Tid
时,你也知道该怎么办吗?不幸的是,我看不到任何方法可以通过api文档通过Tid检索任务。这可能是因为我缺乏感性知识。您是否无法保存任务而不是tid?关于线程安全,这实际上取决于您如何使用它以及我们谈论的安全性。我们说的是同步方面,种族条件方面还是什么?一般来说,在线程安全性方面有很多因素起作用。只要您不尝试检查它是否在其他地方运行,而只是发送状态,它就可以正常工作。