Asynchronism in Action Script 3.0

2019-08-09 00:47发布

问题:

I wonder, how is asynchronism implemented in AS3? Lets take the Timer class. A timer runs asynchronously and dispatches some events. Seems like it creates a new thread for himself. And how are the functions, called when timer event occurs, being thread safe? How is thread safety implemented in AS3?

回答1:

AS3 now supports multi threading using "ActionScript Workers" in the latest build. You can see how it is used here in this preview...

http://www.bytearray.org/?p=4423



回答2:

AS3 [used to be] not multithreaded.

Prior to Flash Player 11.4, everything ran on the main (single) thread, which is why things like Timer classes could be notoriously inaccurate if the CPU gets bogged down with some heavy processing.

As of Flash Player 11.4, Worker objects were introduced, providing the ability to create multiple threads.