A few days ago, I posted an implementation of a Semaphore with AS3. Ever since then, something about the code just didn’t sit right with me. I’ve wanted to research and write about the Liskov substitution principle (LSP) for a while now, and I decided that I would demonstrate it with my Semaphore classes and examples. When I first designed the classes, I thought I was doing a good job, now….not so much. In fact, I think I made errors in my application architecture and overall approach.
(more…)
[Edit] The source code for this has been updated and can be seen and downloaded on this follow up post.
Flash does not support multihreading, and that’s probably good thing since managing threads can be very, very difficult; however, Flash can have a kind of concurrency when it comes to user interface, multi-user applications (e.g. games) and synchronizing animations. With user interfaces, a developer may wish to disable parts or all of the UI while asynchronous events, such as loading assets and managing various animations are executing. Within a multi-user environment, imagine a game where players share a limited amount of resources – checking things in and out as they become available ( see ‘Dining Philosophers Problem‘). Another scenario might be the need to manage many, many animations.
When it comes to concurrency there are various techniques that come to mind – The Semaphore , Java’s ReentrantLock and CountDownLatch, the Actor model, and Scala’s Mailbox. This first post will focus on the semaphore.