Actionscript 3 (as3) 并发模型

发布于 2024-10-17 13:26:52 字数 397 浏览 9 评论 0原文

我在 Actionscript 3 (as3) 程序中有一些竞争条件的证据 [注意:请参阅下面的更新],其中某个对象调用了方法:

  1. 当它处理异步下载事件时
  2. 来自添加到影片剪辑时间轴上的帧的脚本

什么AS3中的并发模型是什么?事件处理是否已序列化(即每个处理程序在一个事件后一个事件中运行完成,尽管有任何底层多线程)?帧中的脚本是否与该事件流一起序列化?我怀疑最后一个问题的答案是否定的。

我正在采取措施系统地记录竞争条件是否/何时发生,但最好知道 AS3 提供了哪些保证(如果有)。

更新:我在事件处理程序中做了一个简单的检查,以记录事件处理程序是否已经在感兴趣的特定对象上进行处理,我发现确实发生了这种情况,即竞争条件是可能的。有其他人遇到过这种情况吗?你对此做了什么?!

I have some evidence of a race condition [Note: see update below] in an Actionscript 3 (as3) program in which a certain object has methods invoked:

  1. When it handles asynchronous download events
  2. From a script added to a frame on a movieclip's timeline

What is the concurrency model in AS3? Is event handling serialised (i.e. each handler runs to completion for one event after the other, despite any underlying multi-threading)? And are scripts in frames serialised with that event stream? I suspect that the answer to that last question is negative.

I'm taking steps to log systematically whether/when a race condition occurs but it would be good to know what guarantees (if any) AS3 provides.

UPDATE: I did a simple check in my event handlers to record whether an event handler was already being processed on the particular object of interest and I found that that does occur, i.e. race conditions are possible. Has anyone else encountered this and what did you do about it?!

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

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

发布评论

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

评论(2

强者自强 2024-10-24 13:26:52

Flash 中不存在“真正的”并发 - 一切(包括事件的处理)都是由主时间线计时。您的所有操作都一定会按照代码中指定的确切顺序执行。

但是,当然,如果您将一个“异步启动”操作块的结果(我将使用这个术语,尽管严格意义上并不完全正确)操作块的结果基于另一个操作块的结果,则可能会出现问题 - 这使用事件处理程序时可能会出现这种情况。您必须找到某种方法以编程方式自行解决这些问题; ActionScript 中没有同步或原子等内置结构,没有线程和锁定或任何其他此类机制。

Flash 中有多种方法可以模拟多线程,这个教程可能是开始搜索解决方案的有趣方式,因为它解释了一些基本概念。

There is no "real" concurrency in Flash - everything, including the handling of events, is clocked by the main timeline. All your operations are certain to execute in the exact order specified in the code.

But of course, problems might occur if you base the result of one "asynchronously started" (I'm going to use this term, although it is not quite correct in a strict sense) block of operations on the outcome of another one - which can be the case when using event handlers. You will have to find some way to solve these issues yourself programmatically; there are no built-in constructs like synchronized or atomic, no threads and locking, or any other such mechanisms in ActionScript.

There are ways to simulate multithreading in Flash, and this tutorial might be an interesting way to start your search for a solution, as it explains some underlying concepts.

时光匆匆的小流年 2024-10-24 13:26:52

您的 AS3 代码只能在一个线程中运行。

异步事件的处理程序中可能存在竞争条件,但与多线程应用程序中的含义不同,并且通常更容易追踪。

例如,您可以开始播放动画并同时加载文件。哪个先完成完全取决于系统。

另一个示例,这并不是真正的竞争条件,但具有类似的症状,即使用 for..in(或 for..each)循环为同一事件添加多个侦听器。侦听器将按照添加顺序接收事件,但 for..in 循环是随机的,因此您将看到随机结果。

There is only one thread that your AS3 code can run in.

Race conditions are possible in handlers for asynchronous events, but not in the same sense as in a multi-threaded application, and are generally easier to track down.

For example, you could start an animation playing and load a file at the same time. Which one completes first is completely system-dependent.

Another example, which isn't really a race condition, but has a similar symptom, is where you use a for..in (or for..each) loop to add multiple listeners for the same event. The listeners will receive the event in the order that they were added, but the for..in loop is random so you'll see random results.

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