1

Summary:

I'm trying to find out if a single method can be executed twice in overlap when executing on a single thread. Or if two different methods can be executed in overlap, where when they share access to a particular variable, some unwanted behaviour can occur.

Ex of a single method:

var ball:Date;

method1 ():Date {

    ball = new Date();

    <some code here>

    return ball;

}

Questions:

1) If method1 gets fired every 20ms using the event system, and the whole method takes more than 20ms to execute, will the method be executed again in overlap?

2) Are there any other scenarios in a single thread environment where a method(s) can be executed in overlap, or is the AVM2 limited to executing 1 method at a time?

Studies: I've read through https://www.adobe.com/content/dam/Adobe/en/devnet/actionscript/articles/avm2overview.pdf which explains that the AVM2 has a stack for running code, and the description for methods makes it seem that if there isn't a second stack, the stack system can only accomodate 1 method execution at a time. I'd just like to double check with the StackeOverflow experts to see for sure.

I'm dealing with some time sensitive data, and have to make sure a method isn't changing a variable that is being accessed by another method at the same time.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98

1 Answers1

2

ActionScript is single-threaded; although, can support concurrency through ActionScript workers, which are multiple SWF applications that run in parallel.

There are asynchronous patterns, if you want a nested function, or anonymous function to execute within the scope chain of a function.

What I think you're referring to is how AVM2 executes event-driven code, to which you should research AVM2 marshalled slice. Player events are executed at the beginning of the slice.

marshalled slice

Heavy code execution will slow frame rate.

elastic racetrack

It's linear - blocking synchronously. Each frame does not invoke code in parallel.

AVM2 executes 20 millisecond marshalled slices, which depending on frame rate executes user actions, invalidations, and rendering.

avm2-slices

Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
  • Great diagrams. Where did you get them from? – Aaron Beall Oct 09 '15 at 14:20
  • 1
    [The Elastic Racetrack](http://www.craftymind.com/updated-elastic-racetrack-for-flash-9-and-avm2/) – Jason Sturges Oct 09 '15 at 14:43
  • Thanks, I've read about the race track before. I was actually confused about how source code is converted into machine code. Quite frankly I probably still am. About what order things are executed it. When writing this question I believed a program has context switching in its core. (context switching between functions.) But in reality it's doing one thing at a time at blasted speeds isn't it. ^^ In other words it will finish executing an entire method before executing the next. – CausingUnderflowsEverywhere Mar 06 '16 at 20:08