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

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 

Recently uploaded (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

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.