SlideShare a Scribd company logo
1 of 78
Concurrent programming with ActionScript workers
     Paul Robertson | Adobe Developer Relations | @probertson |
     http://probertson.com/




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Gratuitous promotion




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   2
Gratuitous promotion

       How can I know what features were added to the Flash runtime
       recently?




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   3
Gratuitous promotion

       How can I know what features were added to the Flash runtime
       recently?
                             http://adobe.ly/O2SRKF




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   4
Why concurrent programming?




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   5
“My UI keeps
                     freezing!”


                                             Why concurrent programming?




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   6
“I want to run
                                                                                   code in the
                   “My UI keeps                                                   background”
                     freezing!”


                                             Why concurrent programming?




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   7
“I want to run
                                                                                               code in the
                   “My UI keeps                                                               background”
                     freezing!”


                                             Why concurrent programming?

                                                                                “Give me
                                                                              multithreaded
                                                                              ActionScript…
                                                                                     ”          “…or give me
                                                                                                  death!”




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   8
Why concurrent programming?

       Flash Runtime’s execution model

            Single threaded
                 All* code runs in a single line of execution
                 This includes your code (event handlers) and runtime’s rendering code




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   9
Why concurrent programming?

       Flash Runtime’s execution model

            Frame model
                 Code execution is scheduled into time units a.k.a. “frames”
                 Length based on frame rate
                 Tries to execute all code in one thread in a frame’s worth of time




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   10
Why concurrent programming?

       For example…




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   11
Why concurrent programming?

       For example…

       Enter frame
                 private function onEnterFrame(event:Event):void




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   12
Why concurrent programming?

       For example…

       Enter frame
                 private function onEnterFrame(event:Event):void
       Mouse event
                 private function onMouseOver(event:MouseEvent):void




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   13
Why concurrent programming?

       For example…

       Enter frame
                 private function onEnterFrame(event:Event):void
       Mouse event
                 private function onMouseOver(event:MouseEvent):void
       Load complete event
                 private function onDataLoad(event:Event):void




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   14
Why concurrent programming?

       For example…

       Enter frame
                 private function onEnterFrame(event:Event):void
       Mouse event
                 private function onMouseOver(event:MouseEvent):void
       Load complete event
                 private function onDataLoad(event:Event):void
       Mouse event
                 private function onClick(event:MouseEvent):void




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   15
Why concurrent programming?

       For example…

       Enter frame
                 private function onEnterFrame(event:Event):void
       Mouse event
                 private function onMouseOver(event:MouseEvent):void
       Load complete event
                 private function onDataLoad(event:Event):void
       Mouse event
                 private function onClick(event:MouseEvent):void
       ...




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   16
Why concurrent programming?

       For example…

       Enter frame
                 private function onEnterFrame(event:Event):void
       Mouse event
                 private function onMouseOver(event:MouseEvent):void
       Load complete event
                 private function onDataLoad(event:Event):void
       Mouse event
                 private function onClick(event:MouseEvent):void
       ...
       Rendering
                 <native player code>




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   17
Why concurrent programming?

       33 ms later…




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   18
Why concurrent programming?

       33 ms later…

       Enter frame
                 private function onEnterFrame(event:Event):void




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   19
Why concurrent programming?

       Now suppose…

       Enter frame
                 private function onEnterFrame(event:Event):void
       Mouse event
                 private function onMouseOver(event:MouseEvent):void
       Load complete event
                 private function onDataLoad(event:Event):void
       Mouse event
                 private function onClick(event:MouseEvent):void
       ...
       Rendering
                 <native player code>




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   20
Why concurrent programming?

       Now suppose…
       Enter frame

                 private function onEnterFrame(event:Event):void

       Mouse event

                 private function onMouseOver(event:MouseEvent):void


       Load complete event
                 private function onDataLoad(event:Event):void
                 {
                             var myXML:XML = _loader.data;
                             for each (var dataPoint:XML in myXML.dataPoint)
                             {
                                                          // parse thousands of XML nodes and create objects
                             }
                 }
       Mouse event

                 private function onClick(event:MouseEvent):void

       ...

       Rendering

                 <native player code>



© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   21
Why concurrent programming?

       > 33 ms later…




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   22
What are Workers?




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   23
What are workers?

       A way to do concurrent programming safely* in ActionScript




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   24
How do they work?




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   25
How do they work?

       Two important architectural needs




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   26
How do they work?

       Two important architectural needs

            Isolate code without language changes




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   27
How do they work?

       Two important architectural needs

            Avoid having to rewrite the entire Flash runtime




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   28
How do they work?

       Solution

            1 SWF = 1 thread

                 Separate instances of AVM


                 Code isolated in SWF




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   29
How do they work?

       Conceptually, it’s like this…




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   30
How do they work?

       Except like this




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   31
What are Workers (redux)?




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   32
What are Workers (redux)?

       A separate AVM instance

       ActionScript object
        Represents a container in which a SWF file executes
                 Yes, that includes non-concurrent apps too




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   33
What are Workers (redux)?




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   34
What are Workers (redux)?




                                               WorkerDomain




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   35
What are Workers (redux)?




                                               WorkerDomain
                                                “Primordial” Worker




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   36
What are Workers (redux)?




                                               WorkerDomain
                                                “Primordial” Worker
                                                     public class App extends Sprite
                                                     {
                                                       // ...
                                                     }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.       37
What are Workers (redux)?




                                               WorkerDomain
                                                “Primordial” Worker
                                                     public class App extends Sprite
                                                     {
                                                       WorkerDomain.current.createWorker();
                                                     }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.     38
What are Workers (redux)?




                                               WorkerDomain
                                                “Primordial” Worker
                                                     public class App extends Sprite
                                                     {
                                                       WorkerDomain.current.createWorker();
                                                     }


                                                   “background” Worker
                                                     public class BGWorker extends Sprite
                                                     {
                                                       // ...
                                                     }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.      39
What are Workers (redux)?




                                               WorkerDomain
                                                “Primordial” Worker
                                                     public class App extends Sprite
                                                     {
                                                       WorkerDomain.current.createWorker();
                                                     }


                                                   “background” Worker
                                                     public class BGWorker extends Sprite
                                                     {
                                                       // ...
                                                     }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.      40
Caveats (part 1)




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.    41
Caveats (part 1)

       Desktop only – not available in mobile AIR

             (for now)




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   42
How do I use a Worker? (in code please)




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   43
How do I use a Worker?

       Step 1. Create the background worker SWF


         public class BGWorker extends Sprite
         {
           // ...
         }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   44
How do I use a Worker?

       Step 2. Get the bytes of the SWF
             [Embed]
         [Embed(source="../swfs/BgWorker.swf", mimeType="application/octet-stream")]
         private static var BgWorker_ByteClass:Class;

         private function createWorker():void
         {
            var workerBytes:ByteArray = new BgWorker_ByteClass();
         }



             Load
          var workerLoader:URLLoader = new URLLoader();
          workerLoader.dataFormat = URLLoaderDataFormat.BINARY;
          workerLoader.addEventListener(Event.COMPLETE, loadComplete);
          workerLoader.load(new URLRequest("BgWorker.swf"));

          private function loadComplete(event:Event):void
          {
             var workerBytes:ByteArray = event.target.data as ByteArray;
          }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   45
How do I use a Worker?

       Step 3. Create the Worker from the WorkerDomain


         [Embed(source="../swfs/BgWorker.swf", mimeType="application/octet-stream")]
         private static var BgWorker_ByteClass:Class;

         private var bgWorker:Worker;

         private function createWorker():void
         {
            var workerBytes:ByteArray = new BgWorker_ByteClass();
            bgWorker = WorkerDomain.current.createWorker(workerBytes);
         }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   46
How do I use a Worker?

       Step 4. Register for the workerState event and start the worker


          [Embed(source="../swfs/BgWorker.swf", mimeType="application/octet-stream")]
          private static var BgWorker_ByteClass:Class;

          private var bgWorker:Worker;

          private function createWorker():void
          {
             var workerBytes:ByteArray = new BgWorker_ByteClass();
             bgWorker = WorkerDomain.current.createWorker(workerBytes);

              bgWorker.addEventListener(Event.WORKER_STATE, workerStateHandler);
              bgWorker.start()
          }

          private function workerStateHandler(event:Event):void
          {
             if (bgWorker.state == WorkerState.RUNNING)
             {
                 // The worker is running -- send it a message or wait
             }
          }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   47
Worker communication




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   48
Worker communication

       Two new communication mechanisms

            Worker shared properties

            MessageChannel




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   49
Worker communication

       Two new communication mechanisms

            Worker shared properties

            MessageChannel



       “Classic” techniques
        Local shared objects

        Write to/read from files

        Server communication

        SQLite database




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   50
Worker communication

       Worker shared properties
        “dictionary” of properties stored in a worker
                 String keys and * values
                 Available for reading and writing from within and outside the worker




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   51
Worker communication

       Worker shared properties
        “dictionary” of properties stored in a worker
                 String keys and * values
                 Available for reading and writing from within and outside the worker
       Setting shared property (e.g. in parent worker):
         bgWorker.setSharedProperty("propertyName", someObject);



       Reading shared property (e.g. in background worker):
          var receivedProperty:Object;
          receivedProperty = Worker.current.getSharedProperty("propertyName");




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   52
Worker communication

       Worker shared properties
        Available even before worker.start() is called

       Parent worker:
         private function createWorker():void
         {
            var workerBytes:ByteArray = new BgWorker_ByteClass();
            bgWorker = WorkerDomain.current.createWorker(workerBytes);
            bgWorker.setSharedProperty("propertyName", someObject);
            bgWorker.addEventListener(Event.WORKER_STATE, workerStateHandler);
            bgWorker.start()
         }



       Background worker:
          public class BGWorker extends Sprite
          {
            public function BGWorker()
            {
               var receivedProperty:Object;
               receivedProperty = Worker.current.getSharedProperty("propertyName");
            }
          }


© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   53
Worker communication

       MessageChannel
        One-way data-passing channel
                 One worker is the “sender,” another is the “receiver”
            When a message is sent, MessageChannel dispatches an event




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   54
Worker communication

       Step 1. Sending worker creates the MessageChannel

             Code in the sending worker:
         var sendChannel:MessageChannel;
         sendChannel = Worker.current.createMessageChannel(receivingWorker);




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   55
Worker communication

       Step 2. Sending worker passes the MessageChannel to the receiver

             Code in the sending worker:
         var sendChannel:MessageChannel;
         sendChannel = Worker.current.createMessageChannel(receivingWorker);

         receivingWorker.setSharedProperty("incomingChannel", sendChannel);




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   56
Worker communication

       Step 3. Receiving worker gets the MessageChannel object

             Code in the receiving worker:
         var incomingChannel:MessageChannel;
         incomingChannel = Worker.current.getSharedProperty("incomingChannel");




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   57
Worker communication

       Step 4. Receiving worker listens for the channelMessage event

             Code in the receiving worker:
         var incomingChannel:MessageChannel;
         incomingChannel = Worker.current.getSharedProperty("incomingChannel");

         incomingChannel.addEventListener(Event.CHANNEL_MESSAGE, handleIncomingMessage);




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   58
Worker communication

       Step 5. Sending worker calls the MessageChannel’s send() method

             Code in the sending worker:
         var sendChannel:MessageChannel;
         sendChannel = Worker.current.createMessageChannel(receivingWorker);

         receivingWorker.setSharedProperty("incomingChannel", sendChannel);

         // ...

         sendChannel.send("This is a message");




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   59
Worker communication

       Step 6. Receiving worker handles the channelMessage event

             Code in the receiving worker:
         var incomingChannel:MessageChannel;
         incomingChannel = Worker.current.getSharedProperty("incomingChannel");

         incomingChannel.addEventListener(Event.CHANNEL_MESSAGE, handleIncomingMessage);


         private function handleIncomingMessage(event:Event):void
         {
            var message:String = incomingChannel.receive() as String;
         }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   60
Worker communication

       Object passing rules




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   61
Worker communication

       Object passing rules

       Objects passed to setSharedProperty() or MessageChannel.send()
       are…




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   62
Worker communication

       Object passing rules

       Objects passed to setSharedProperty() or MessageChannel.send()
       are…
             …Serialized in AMF format by sending worker




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   63
Worker communication

       Object passing rules

       Objects passed to setSharedProperty() or MessageChannel.send()
       are…
             …Serialized in AMF format by sending worker
             …Deserialized by receiving worker




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   64
Worker communication

       Object passing rules

       Side effects of using AMF




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   65
Worker communication

       Object passing rules

       Side effects of using AMF:
                 Object in receiver is a copy, not a reference




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   66
Worker communication

       Object passing rules

       Side effects of using AMF:
                 Objects that can’t be serialized in AMF can’t be passed




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   67
Worker communication

       Object passing rules

       Two exceptions:
        Worker

        MessageChannel




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   68
Caveats (part 2)




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.    69
Caveats (part 2)

       Code execution order is no longer guaranteed (across workers)

             e.g. setting a breakpoint makes code nondeterministic




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   70
Caveats (part 2)

       Performance impact

             “Adobe recommends that you do not use more than
             one or two background workers in a typical scenario.”




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   71
“Crystal Ball”




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.         72
“Crystal Ball”

       Shareable ByteArray

            Avoid AMF overhead
            Especially useful when data is binary by nature (e.g. BitmapData)




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   73
“Crystal Ball”

       Mutex

            “Mutually exclusive” access to shared resource
             lock()
             tryLock()
             unlock()




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   74
“Crystal Ball”

       Mobile AIR




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   75
“Crystal Ball”

       Language features

             Warning: totally made up pseudocode:
         public class MyClass
         {
           public function doSomething():void
           {
              // do some stuff in the main thread

                  backgroundThread
                  {
                    // do something in the background
                    // using variables/methods that are in scope
                  }

                  // do more in the main thread
             }
         }




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   76
Thank you and Q&A




© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.   77
© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

More Related Content

Viewers also liked

GCIS Government Communication and Information Systems
GCIS Government Communication and Information SystemsGCIS Government Communication and Information Systems
GCIS Government Communication and Information SystemsCourtney Bentley
 
Триггеры – «спусковые крючки» принятия решений
Триггеры – «спусковые крючки» принятия решенийТриггеры – «спусковые крючки» принятия решений
Триггеры – «спусковые крючки» принятия решений"Rating Runet"
 
The Top 10 Most Socially Marketable Tennis Athletes
The Top 10 Most Socially Marketable Tennis AthletesThe Top 10 Most Socially Marketable Tennis Athletes
The Top 10 Most Socially Marketable Tennis AthletesAdobe
 
Sex, Lies and Instant Messenger v1
Sex, Lies and Instant Messenger v1Sex, Lies and Instant Messenger v1
Sex, Lies and Instant Messenger v1Alec Muffett
 
(NET406) Deep Dive: AWS Direct Connect and VPNs
(NET406) Deep Dive: AWS Direct Connect and VPNs(NET406) Deep Dive: AWS Direct Connect and VPNs
(NET406) Deep Dive: AWS Direct Connect and VPNsAmazon Web Services
 
Social Media Crisis Management: Three Case Studies
Social Media Crisis Management: Three Case StudiesSocial Media Crisis Management: Three Case Studies
Social Media Crisis Management: Three Case StudiesElisha Tan
 
Tapworthy: Designing iPhone Interfaces for Delight and Usability
Tapworthy: Designing iPhone Interfaces for Delight and UsabilityTapworthy: Designing iPhone Interfaces for Delight and Usability
Tapworthy: Designing iPhone Interfaces for Delight and UsabilityJosh Clark
 
On-demand Transport Technology Companies around the World - Top 30 Players
On-demand Transport Technology Companies around the World - Top 30 PlayersOn-demand Transport Technology Companies around the World - Top 30 Players
On-demand Transport Technology Companies around the World - Top 30 PlayersValoriser Consultants
 
Data Visualization Meets Visual Storytelling
Data Visualization Meets Visual StorytellingData Visualization Meets Visual Storytelling
Data Visualization Meets Visual StorytellingJESS3
 
Leadership Games and Activities
Leadership Games and ActivitiesLeadership Games and Activities
Leadership Games and ActivitiesLacey
 
What Do Real Women Look Like? 100 Stock Photos of Real Women
What Do Real Women Look Like? 100 Stock Photos of Real WomenWhat Do Real Women Look Like? 100 Stock Photos of Real Women
What Do Real Women Look Like? 100 Stock Photos of Real WomenTwenty20 Inc.
 
Practice management in dentistry
Practice management in dentistryPractice management in dentistry
Practice management in dentistryammar905
 
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)Savita Marwal
 
Bootstrap Business Seminar 5: Creating an Awesome Brand
Bootstrap Business Seminar 5: Creating an Awesome BrandBootstrap Business Seminar 5: Creating an Awesome Brand
Bootstrap Business Seminar 5: Creating an Awesome BrandCityStarters
 

Viewers also liked (14)

GCIS Government Communication and Information Systems
GCIS Government Communication and Information SystemsGCIS Government Communication and Information Systems
GCIS Government Communication and Information Systems
 
Триггеры – «спусковые крючки» принятия решений
Триггеры – «спусковые крючки» принятия решенийТриггеры – «спусковые крючки» принятия решений
Триггеры – «спусковые крючки» принятия решений
 
The Top 10 Most Socially Marketable Tennis Athletes
The Top 10 Most Socially Marketable Tennis AthletesThe Top 10 Most Socially Marketable Tennis Athletes
The Top 10 Most Socially Marketable Tennis Athletes
 
Sex, Lies and Instant Messenger v1
Sex, Lies and Instant Messenger v1Sex, Lies and Instant Messenger v1
Sex, Lies and Instant Messenger v1
 
(NET406) Deep Dive: AWS Direct Connect and VPNs
(NET406) Deep Dive: AWS Direct Connect and VPNs(NET406) Deep Dive: AWS Direct Connect and VPNs
(NET406) Deep Dive: AWS Direct Connect and VPNs
 
Social Media Crisis Management: Three Case Studies
Social Media Crisis Management: Three Case StudiesSocial Media Crisis Management: Three Case Studies
Social Media Crisis Management: Three Case Studies
 
Tapworthy: Designing iPhone Interfaces for Delight and Usability
Tapworthy: Designing iPhone Interfaces for Delight and UsabilityTapworthy: Designing iPhone Interfaces for Delight and Usability
Tapworthy: Designing iPhone Interfaces for Delight and Usability
 
On-demand Transport Technology Companies around the World - Top 30 Players
On-demand Transport Technology Companies around the World - Top 30 PlayersOn-demand Transport Technology Companies around the World - Top 30 Players
On-demand Transport Technology Companies around the World - Top 30 Players
 
Data Visualization Meets Visual Storytelling
Data Visualization Meets Visual StorytellingData Visualization Meets Visual Storytelling
Data Visualization Meets Visual Storytelling
 
Leadership Games and Activities
Leadership Games and ActivitiesLeadership Games and Activities
Leadership Games and Activities
 
What Do Real Women Look Like? 100 Stock Photos of Real Women
What Do Real Women Look Like? 100 Stock Photos of Real WomenWhat Do Real Women Look Like? 100 Stock Photos of Real Women
What Do Real Women Look Like? 100 Stock Photos of Real Women
 
Practice management in dentistry
Practice management in dentistryPractice management in dentistry
Practice management in dentistry
 
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
Payment and Settlement Systems(SWIFT,NEFT and Securities Cycle)
 
Bootstrap Business Seminar 5: Creating an Awesome Brand
Bootstrap Business Seminar 5: Creating an Awesome BrandBootstrap Business Seminar 5: Creating an Awesome Brand
Bootstrap Business Seminar 5: Creating an Awesome Brand
 

Similar to Concurrent Programming with ActionScript workers

ColdFusion 11 Overview - CFSummit 2013
ColdFusion 11 Overview - CFSummit 2013ColdFusion 11 Overview - CFSummit 2013
ColdFusion 11 Overview - CFSummit 2013Rupesh Kumar
 
Using Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component SetUsing Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component SetJoseph Labrecque
 
Over the air 2.5 - Adobe AIR for Android
Over the air 2.5 - Adobe AIR for AndroidOver the air 2.5 - Adobe AIR for Android
Over the air 2.5 - Adobe AIR for AndroidMichael Chaize
 
Better Code: Concurrency
Better Code: ConcurrencyBetter Code: Concurrency
Better Code: ConcurrencyPlatonov Sergey
 
What is Codename One.pdf
What is Codename One.pdfWhat is Codename One.pdf
What is Codename One.pdfShaiAlmog1
 
WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014Minko3D
 
Progressing beyond the Desktop at Universities with Adobe AIR
Progressing beyond the Desktop at Universities with Adobe AIRProgressing beyond the Desktop at Universities with Adobe AIR
Progressing beyond the Desktop at Universities with Adobe AIRJoseph Labrecque
 
Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012jobandesther
 
ANDROID presentation prabal
ANDROID presentation prabalANDROID presentation prabal
ANDROID presentation prabalPrabal Tyagi
 
Node.js and Photoshop Generator - JSConf Asia 2013
Node.js and Photoshop Generator - JSConf Asia 2013Node.js and Photoshop Generator - JSConf Asia 2013
Node.js and Photoshop Generator - JSConf Asia 2013Andy Hall
 
WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is nearBartlomiej Filipek
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch EventJames Montemagno
 
Tom Krcha: Building Games with Adobe Technologies
Tom Krcha: Building Games with Adobe TechnologiesTom Krcha: Building Games with Adobe Technologies
Tom Krcha: Building Games with Adobe TechnologiesDevGAMM Conference
 
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...Carl Tyler
 
AD106 - IBM Lotus Domino XPages anywhere - Write them once, See them Everywhere
AD106 - IBM Lotus Domino XPages anywhere - Write them once, See them EverywhereAD106 - IBM Lotus Domino XPages anywhere - Write them once, See them Everywhere
AD106 - IBM Lotus Domino XPages anywhere - Write them once, See them EverywhereStephan H. Wissel
 
Adobe Session on Flash Online Conference #12
Adobe Session on Flash Online Conference #12Adobe Session on Flash Online Conference #12
Adobe Session on Flash Online Conference #12Flash Conference
 
Applico Android Info Session at Columbia University
Applico Android Info Session at Columbia UniversityApplico Android Info Session at Columbia University
Applico Android Info Session at Columbia UniversityApplico
 
User Interface customization for AEM 6
User Interface customization for AEM 6User Interface customization for AEM 6
User Interface customization for AEM 6Damien Antipa
 
Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the CloudSimona Cotin
 

Similar to Concurrent Programming with ActionScript workers (20)

ColdFusion 11 Overview - CFSummit 2013
ColdFusion 11 Overview - CFSummit 2013ColdFusion 11 Overview - CFSummit 2013
ColdFusion 11 Overview - CFSummit 2013
 
Using Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component SetUsing Edge Animate to Create a Reusable Component Set
Using Edge Animate to Create a Reusable Component Set
 
Over the air 2.5 - Adobe AIR for Android
Over the air 2.5 - Adobe AIR for AndroidOver the air 2.5 - Adobe AIR for Android
Over the air 2.5 - Adobe AIR for Android
 
Better Code: Concurrency
Better Code: ConcurrencyBetter Code: Concurrency
Better Code: Concurrency
 
Flex mobile for JUG
Flex mobile for JUGFlex mobile for JUG
Flex mobile for JUG
 
What is Codename One.pdf
What is Codename One.pdfWhat is Codename One.pdf
What is Codename One.pdf
 
WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014
 
Progressing beyond the Desktop at Universities with Adobe AIR
Progressing beyond the Desktop at Universities with Adobe AIRProgressing beyond the Desktop at Universities with Adobe AIR
Progressing beyond the Desktop at Universities with Adobe AIR
 
Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012Code and Conquer with Globe Labs, October 27, 2012
Code and Conquer with Globe Labs, October 27, 2012
 
ANDROID presentation prabal
ANDROID presentation prabalANDROID presentation prabal
ANDROID presentation prabal
 
Node.js and Photoshop Generator - JSConf Asia 2013
Node.js and Photoshop Generator - JSConf Asia 2013Node.js and Photoshop Generator - JSConf Asia 2013
Node.js and Photoshop Generator - JSConf Asia 2013
 
WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is near
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch Event
 
Tom Krcha: Building Games with Adobe Technologies
Tom Krcha: Building Games with Adobe TechnologiesTom Krcha: Building Games with Adobe Technologies
Tom Krcha: Building Games with Adobe Technologies
 
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
 
AD106 - IBM Lotus Domino XPages anywhere - Write them once, See them Everywhere
AD106 - IBM Lotus Domino XPages anywhere - Write them once, See them EverywhereAD106 - IBM Lotus Domino XPages anywhere - Write them once, See them Everywhere
AD106 - IBM Lotus Domino XPages anywhere - Write them once, See them Everywhere
 
Adobe Session on Flash Online Conference #12
Adobe Session on Flash Online Conference #12Adobe Session on Flash Online Conference #12
Adobe Session on Flash Online Conference #12
 
Applico Android Info Session at Columbia University
Applico Android Info Session at Columbia UniversityApplico Android Info Session at Columbia University
Applico Android Info Session at Columbia University
 
User Interface customization for AEM 6
User Interface customization for AEM 6User Interface customization for AEM 6
User Interface customization for AEM 6
 
Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the Cloud
 

Recently uploaded

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Recently uploaded (20)

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

Concurrent Programming with ActionScript workers

  • 1. Concurrent programming with ActionScript workers Paul Robertson | Adobe Developer Relations | @probertson | http://probertson.com/ © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  • 2. Gratuitous promotion © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 2
  • 3. Gratuitous promotion How can I know what features were added to the Flash runtime recently? © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 3
  • 4. Gratuitous promotion How can I know what features were added to the Flash runtime recently? http://adobe.ly/O2SRKF © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 4
  • 5. Why concurrent programming? © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 5
  • 6. “My UI keeps freezing!” Why concurrent programming? © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 6
  • 7. “I want to run code in the “My UI keeps background” freezing!” Why concurrent programming? © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 7
  • 8. “I want to run code in the “My UI keeps background” freezing!” Why concurrent programming? “Give me multithreaded ActionScript… ” “…or give me death!” © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 8
  • 9. Why concurrent programming? Flash Runtime’s execution model  Single threaded  All* code runs in a single line of execution  This includes your code (event handlers) and runtime’s rendering code © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 9
  • 10. Why concurrent programming? Flash Runtime’s execution model  Frame model  Code execution is scheduled into time units a.k.a. “frames”  Length based on frame rate  Tries to execute all code in one thread in a frame’s worth of time © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 10
  • 11. Why concurrent programming? For example… © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 11
  • 12. Why concurrent programming? For example… Enter frame private function onEnterFrame(event:Event):void © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 12
  • 13. Why concurrent programming? For example… Enter frame private function onEnterFrame(event:Event):void Mouse event private function onMouseOver(event:MouseEvent):void © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 13
  • 14. Why concurrent programming? For example… Enter frame private function onEnterFrame(event:Event):void Mouse event private function onMouseOver(event:MouseEvent):void Load complete event private function onDataLoad(event:Event):void © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 14
  • 15. Why concurrent programming? For example… Enter frame private function onEnterFrame(event:Event):void Mouse event private function onMouseOver(event:MouseEvent):void Load complete event private function onDataLoad(event:Event):void Mouse event private function onClick(event:MouseEvent):void © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 15
  • 16. Why concurrent programming? For example… Enter frame private function onEnterFrame(event:Event):void Mouse event private function onMouseOver(event:MouseEvent):void Load complete event private function onDataLoad(event:Event):void Mouse event private function onClick(event:MouseEvent):void ... © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 16
  • 17. Why concurrent programming? For example… Enter frame private function onEnterFrame(event:Event):void Mouse event private function onMouseOver(event:MouseEvent):void Load complete event private function onDataLoad(event:Event):void Mouse event private function onClick(event:MouseEvent):void ... Rendering <native player code> © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 17
  • 18. Why concurrent programming? 33 ms later… © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 18
  • 19. Why concurrent programming? 33 ms later… Enter frame private function onEnterFrame(event:Event):void © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 19
  • 20. Why concurrent programming? Now suppose… Enter frame private function onEnterFrame(event:Event):void Mouse event private function onMouseOver(event:MouseEvent):void Load complete event private function onDataLoad(event:Event):void Mouse event private function onClick(event:MouseEvent):void ... Rendering <native player code> © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 20
  • 21. Why concurrent programming? Now suppose… Enter frame private function onEnterFrame(event:Event):void Mouse event private function onMouseOver(event:MouseEvent):void Load complete event private function onDataLoad(event:Event):void { var myXML:XML = _loader.data; for each (var dataPoint:XML in myXML.dataPoint) { // parse thousands of XML nodes and create objects } } Mouse event private function onClick(event:MouseEvent):void ... Rendering <native player code> © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 21
  • 22. Why concurrent programming? > 33 ms later… © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 22
  • 23. What are Workers? © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 23
  • 24. What are workers? A way to do concurrent programming safely* in ActionScript © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 24
  • 25. How do they work? © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 25
  • 26. How do they work? Two important architectural needs © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 26
  • 27. How do they work? Two important architectural needs  Isolate code without language changes © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 27
  • 28. How do they work? Two important architectural needs  Avoid having to rewrite the entire Flash runtime © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 28
  • 29. How do they work? Solution  1 SWF = 1 thread  Separate instances of AVM  Code isolated in SWF © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 29
  • 30. How do they work? Conceptually, it’s like this… © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 30
  • 31. How do they work? Except like this © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 31
  • 32. What are Workers (redux)? © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 32
  • 33. What are Workers (redux)? A separate AVM instance ActionScript object  Represents a container in which a SWF file executes  Yes, that includes non-concurrent apps too © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 33
  • 34. What are Workers (redux)? © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 34
  • 35. What are Workers (redux)? WorkerDomain © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 35
  • 36. What are Workers (redux)? WorkerDomain “Primordial” Worker © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 36
  • 37. What are Workers (redux)? WorkerDomain “Primordial” Worker public class App extends Sprite { // ... } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 37
  • 38. What are Workers (redux)? WorkerDomain “Primordial” Worker public class App extends Sprite { WorkerDomain.current.createWorker(); } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 38
  • 39. What are Workers (redux)? WorkerDomain “Primordial” Worker public class App extends Sprite { WorkerDomain.current.createWorker(); } “background” Worker public class BGWorker extends Sprite { // ... } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 39
  • 40. What are Workers (redux)? WorkerDomain “Primordial” Worker public class App extends Sprite { WorkerDomain.current.createWorker(); } “background” Worker public class BGWorker extends Sprite { // ... } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 40
  • 41. Caveats (part 1) © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 41
  • 42. Caveats (part 1) Desktop only – not available in mobile AIR (for now) © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 42
  • 43. How do I use a Worker? (in code please) © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 43
  • 44. How do I use a Worker? Step 1. Create the background worker SWF public class BGWorker extends Sprite { // ... } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 44
  • 45. How do I use a Worker? Step 2. Get the bytes of the SWF [Embed] [Embed(source="../swfs/BgWorker.swf", mimeType="application/octet-stream")] private static var BgWorker_ByteClass:Class; private function createWorker():void { var workerBytes:ByteArray = new BgWorker_ByteClass(); } Load var workerLoader:URLLoader = new URLLoader(); workerLoader.dataFormat = URLLoaderDataFormat.BINARY; workerLoader.addEventListener(Event.COMPLETE, loadComplete); workerLoader.load(new URLRequest("BgWorker.swf")); private function loadComplete(event:Event):void { var workerBytes:ByteArray = event.target.data as ByteArray; } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 45
  • 46. How do I use a Worker? Step 3. Create the Worker from the WorkerDomain [Embed(source="../swfs/BgWorker.swf", mimeType="application/octet-stream")] private static var BgWorker_ByteClass:Class; private var bgWorker:Worker; private function createWorker():void { var workerBytes:ByteArray = new BgWorker_ByteClass(); bgWorker = WorkerDomain.current.createWorker(workerBytes); } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 46
  • 47. How do I use a Worker? Step 4. Register for the workerState event and start the worker [Embed(source="../swfs/BgWorker.swf", mimeType="application/octet-stream")] private static var BgWorker_ByteClass:Class; private var bgWorker:Worker; private function createWorker():void { var workerBytes:ByteArray = new BgWorker_ByteClass(); bgWorker = WorkerDomain.current.createWorker(workerBytes); bgWorker.addEventListener(Event.WORKER_STATE, workerStateHandler); bgWorker.start() } private function workerStateHandler(event:Event):void { if (bgWorker.state == WorkerState.RUNNING) { // The worker is running -- send it a message or wait } } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 47
  • 48. Worker communication © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 48
  • 49. Worker communication Two new communication mechanisms  Worker shared properties  MessageChannel © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 49
  • 50. Worker communication Two new communication mechanisms  Worker shared properties  MessageChannel “Classic” techniques  Local shared objects  Write to/read from files  Server communication  SQLite database © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 50
  • 51. Worker communication Worker shared properties  “dictionary” of properties stored in a worker  String keys and * values  Available for reading and writing from within and outside the worker © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 51
  • 52. Worker communication Worker shared properties  “dictionary” of properties stored in a worker  String keys and * values  Available for reading and writing from within and outside the worker Setting shared property (e.g. in parent worker): bgWorker.setSharedProperty("propertyName", someObject); Reading shared property (e.g. in background worker): var receivedProperty:Object; receivedProperty = Worker.current.getSharedProperty("propertyName"); © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 52
  • 53. Worker communication Worker shared properties  Available even before worker.start() is called Parent worker: private function createWorker():void { var workerBytes:ByteArray = new BgWorker_ByteClass(); bgWorker = WorkerDomain.current.createWorker(workerBytes); bgWorker.setSharedProperty("propertyName", someObject); bgWorker.addEventListener(Event.WORKER_STATE, workerStateHandler); bgWorker.start() } Background worker: public class BGWorker extends Sprite { public function BGWorker() { var receivedProperty:Object; receivedProperty = Worker.current.getSharedProperty("propertyName"); } } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 53
  • 54. Worker communication MessageChannel  One-way data-passing channel  One worker is the “sender,” another is the “receiver”  When a message is sent, MessageChannel dispatches an event © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 54
  • 55. Worker communication Step 1. Sending worker creates the MessageChannel Code in the sending worker: var sendChannel:MessageChannel; sendChannel = Worker.current.createMessageChannel(receivingWorker); © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 55
  • 56. Worker communication Step 2. Sending worker passes the MessageChannel to the receiver Code in the sending worker: var sendChannel:MessageChannel; sendChannel = Worker.current.createMessageChannel(receivingWorker); receivingWorker.setSharedProperty("incomingChannel", sendChannel); © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 56
  • 57. Worker communication Step 3. Receiving worker gets the MessageChannel object Code in the receiving worker: var incomingChannel:MessageChannel; incomingChannel = Worker.current.getSharedProperty("incomingChannel"); © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 57
  • 58. Worker communication Step 4. Receiving worker listens for the channelMessage event Code in the receiving worker: var incomingChannel:MessageChannel; incomingChannel = Worker.current.getSharedProperty("incomingChannel"); incomingChannel.addEventListener(Event.CHANNEL_MESSAGE, handleIncomingMessage); © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 58
  • 59. Worker communication Step 5. Sending worker calls the MessageChannel’s send() method Code in the sending worker: var sendChannel:MessageChannel; sendChannel = Worker.current.createMessageChannel(receivingWorker); receivingWorker.setSharedProperty("incomingChannel", sendChannel); // ... sendChannel.send("This is a message"); © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 59
  • 60. Worker communication Step 6. Receiving worker handles the channelMessage event Code in the receiving worker: var incomingChannel:MessageChannel; incomingChannel = Worker.current.getSharedProperty("incomingChannel"); incomingChannel.addEventListener(Event.CHANNEL_MESSAGE, handleIncomingMessage); private function handleIncomingMessage(event:Event):void { var message:String = incomingChannel.receive() as String; } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 60
  • 61. Worker communication Object passing rules © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 61
  • 62. Worker communication Object passing rules Objects passed to setSharedProperty() or MessageChannel.send() are… © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 62
  • 63. Worker communication Object passing rules Objects passed to setSharedProperty() or MessageChannel.send() are… …Serialized in AMF format by sending worker © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 63
  • 64. Worker communication Object passing rules Objects passed to setSharedProperty() or MessageChannel.send() are… …Serialized in AMF format by sending worker …Deserialized by receiving worker © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 64
  • 65. Worker communication Object passing rules Side effects of using AMF © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 65
  • 66. Worker communication Object passing rules Side effects of using AMF:  Object in receiver is a copy, not a reference © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 66
  • 67. Worker communication Object passing rules Side effects of using AMF:  Objects that can’t be serialized in AMF can’t be passed © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 67
  • 68. Worker communication Object passing rules Two exceptions:  Worker  MessageChannel © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 68
  • 69. Caveats (part 2) © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 69
  • 70. Caveats (part 2) Code execution order is no longer guaranteed (across workers) e.g. setting a breakpoint makes code nondeterministic © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 70
  • 71. Caveats (part 2) Performance impact “Adobe recommends that you do not use more than one or two background workers in a typical scenario.” © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 71
  • 72. “Crystal Ball” © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 72
  • 73. “Crystal Ball” Shareable ByteArray  Avoid AMF overhead  Especially useful when data is binary by nature (e.g. BitmapData) © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 73
  • 74. “Crystal Ball” Mutex  “Mutually exclusive” access to shared resource lock() tryLock() unlock() © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 74
  • 75. “Crystal Ball” Mobile AIR © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 75
  • 76. “Crystal Ball” Language features Warning: totally made up pseudocode: public class MyClass { public function doSomething():void { // do some stuff in the main thread backgroundThread { // do something in the background // using variables/methods that are in scope } // do more in the main thread } } © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 76
  • 77. Thank you and Q&A © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 77
  • 78. © 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Editor's Notes

  1. Need a way to make it easy and obvious what code is allowed to call other codecf. other background operations that run developer code: SQLite database, Pixel Bender shaders
  2. At this point (when the worker’s start() method is called) the runtime creates the new AVM instance, loads the worker SWF into it, and calls the worker SWF’s main class’s constructor.