延续(如 Smalltalk 中)和中断(如汇编器中)有什么区别?

发布于 2024-07-18 20:05:32 字数 220 浏览 13 评论 0原文

我正在努力理解延续的概念(如 Seaside with Smalltalk 中使用的)。 维基百科的一个片段说:

“...指的是一流的延续,这些结构使编程语言能够在任何点保存执行状态并在程序的稍后点返回到该点...”

这不是简单吗表达汇编程序员在编程中断时会做什么的另一种方式? 或者我完全没有抓住重点!

I'm struggling to understand the concept of Continuations (as used in Seaside with Smalltalk). A snippet from Wikipedia says:

"... refer to first-class continuations, which are constructs that give a programming language the ability to save the execution state at any point and return to that point at a later point in the program..."

Isn't this simply another way of expressing what an assembler programmer would do when programming an interrupt? Or have I completely missed the point!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情感失落者 2024-07-25 20:05:32

延续可以被视为正在运行的流程的快照副本。 捕获延续意味着当前进程被复制并放在一边。 之后,代码继续正常执行。 评估延续意味着当前进程终止,复制的进程将恢复到捕获时的状态。 延续通常可以多次恢复。

中断更像是一个协程,其中有两个相互交错的不同执行线程(应用程序代码、中断处理程序)。

A continuation can be seen as a snapshot copy of the running process. Capturing a continuation means that the current process is copied and put aside. After that, code continues to execute normally. Evaluating a continuation means that the current process is terminated and the copied one is resumed in exactly the state it was captured. Continuations can typically be resumed multiple times.

An interrupt is more like a coroutine, where there are two different execution threads (application code, interrupt handler) that interleave each other.

一身仙ぐ女味 2024-07-25 20:05:32

延续大致相当于 C 中的 setjump/longjump。当您在离开延续后调用延续(堆栈、标志、寄存器、指令指针等)时,您可以期望上下文完好无损。 因此,它类似于软件中断调用,只不过您不必在处理程序完成后返回(或更准确地说,调用延续)并且延续不是隐式的。

Continuations are roughly equivalent to setjump/longjump in C. You can expect your context be intact when you call the continuation (stack, flags, registers, instruction pointer and so on) after leaving it. So it is similar to a software interrupt call except you don't have to return (or more accurately, call the continuation) after the handler finishes and the continuation is not implicit.

仙女山的月亮 2024-07-25 20:05:32

在某些方面它们是相似的。 然而,延续是由程序本身调用的,而中断通常是由CPU或计算机上的设备产生的。 另外,中断更像是 C 信号,它只是被调用,然后控制权返回到程序。 中断负责保存状态并随后恢复状态。

另外,应该注意的是,您可以在汇编程序中非常轻松地实现延续。

In some ways they are similar. However, continuations are called by the program itself, and interrupts are usually generated by the CPU or devices on the computer. Also, an interrupt is more like a C signal, it is just called and then control returns to the program. The interrupt is responsible for saving state and restoring it afterwards.

Also, it should be noted that you can implement continuations quite easily in assembler.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文