Smalltalk:一个对象可以通过进入无限循环来阻塞整个系统吗? [英] Smalltalk: Can a single object block the entire system by entering an infinite loop?

查看:60
本文介绍了Smalltalk:一个对象可以通过进入无限循环来阻塞整个系统吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Smalltalk调度是非抢占式的,因此进程必须显式产生或等待信号量

Since Smalltalk scheduling is non-preemptive, processes must explicitly yield or wait on a semaphore

这是否意味着一个进入无限循环的对象可能会使整个系统停滞不前?

Does this mean that one object entering an infinite loop could stall the entire system?

循环可以随时中断.即使是像[true] whileTrue之类的原子循环,也可以在执行"之前中断.真正的对象

the loop can be interrupted at any time. Even an atomic loop like [true] whileTrue can be interrupted before "executing" the true object

凭什么可以打断?

推荐答案

是虚拟机可能会中断映像.在正常的执行流程下,VM基本上是一个接一个地发送消息.但是,如果需要,某些事件可能会通过中断执行来影响执行的自然流程.虽然具体示例可能会从一种方言更改为另一种方言,但这些示例通常对应于OS事件,需要将其传达给图像以供考虑.

It is the Virtual Machine who may interrupt the image. Under a normal execution flow, the VM is basically sending messages, one after the other. However, certain events may impact the natural flow of execution by interrupting it, if needed. While concrete examples may change from one dialect to the other, these usually correspond to OS events that need to be communicated to the image for their consideration.

如果VM内存不足,也可能导致中断.在这种情况下,它将中断要求其进行垃圾收集的图像.

An interruption may also be caused if the VM is running out of memory. In this case it will interrupt the image requesting it to do garbage collection.

循环很有趣,因为它们具有常规消息的语义,因此,每次循环重复时,都会对循环内的代码块( #value 和朋友)进行评估.因此,您应该将循环视为常规消息.但是,通常会优化此语义,因此Smalltalk消息不会明确要求重新评估.在这种情况下,VM将在执行块之前检查中断.因此,如果您运行

Loops are interesting because they have the semantics of regular messages, so what happens is that the block of code inside the loop is evaluated (#value & friends) every time the loop repeats. So, you should think of loops as regular messages. However, this semantics is usually optimized so the re-evaluation is not explicitly requested by a Smalltalk message. In that case the VM will check for interruptions before executing the block. Thus, if you run

[true] whileTrue

在将对象 true 指定为当前接收者(在这种情况下,没有消息)之前,VM将检查是否有任何中断要注意(以与检查中断相同的方式)在开始执行任何给定方法之前.

before designating the object true as the current receiver (in this case, of no message) the VM will check whether there is any interrupt to pay attention to (in the same way it checks for interruptions before starting to execute any given method).

大多数方言实现了一些中断"功能.会产生停止"状态的击键并打开调试器供程序员恢复手动控制.

Most dialects implement some "break" keystroke that would produce a "halt" and open a debugger for the programmer to recover manual control.

请注意,根据方言的不同,中断可能仅包含信号量的信号.这样可以将等待的进程(如果有)移到 ProcessScheduler 的就绪队列中.因此,预期的例行程序"被称为常规".可能不会立即运行,但在下一次有流程切换(处于该优先级)时会更改为就绪状态.

Note that, depending on the dialect, an interruption may only consist of the signaling of a semaphore. This will have the effect of moving the waiting process (if any) to the ready queue of the ProcessScheduler. So, the intended "routine" may not run immediately but change to the ready state for the next time there is a process switch (at that level of priority).

想到的最后一个例子是 StackOverflow 异常(无双关),VM意识到它已耗尽堆栈空间,并通过发出异常信号来中断映像.

The last example that comes to mind is the StackOverflow exception (no pun intended), where the VM realizes that it is running out of stack space and interrupts the image by signaling an exception.

您还可以将 #messageNotUnderstood:视为VM意识到对象已接收到的消息,而该消息没有实现时所产生的中断.在这种情况下,自然流将发生变化,以使对象将收到以实际消息作为参数的消息 #messageNotUnderstood:.

You may also think of the #messageNotUnderstood: as an interruption generated by the VM when it realizes that an object has received a message for which is has no implementation. In this case, the natural flow will change so that the object will receive the message #messageNotUnderstood: with the actual message as the argument.

还有一件事.循环是否可能使系统停止运行取决于系统正在运行的进程的优先级.如果循环以低优先级运行,则唤醒优先级较高的进程的中断将优先处理,并在循环进入睡眠状态时运行.按照同样的逻辑,如果您的无限循环以更高的优先级在进程中运行,那么中断不会停止它.

One more thing. Whether a loop may or may not stall the system depends on the priority of the process it is running. If the loop is running with low priority an interruption that awakes a process of higher priority will take precedence and be run while the loop is sent to sleep. By the same logic, if your endless loop runs in a process at a higher priority no interruption will stop it.

这篇关于Smalltalk:一个对象可以通过进入无限循环来阻塞整个系统吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆