1 / 11

IO Concurrency

IO Concurrency. Kurt Niemi CPSC 5135 Spring Semester 2011. Main Components. These are the major components in IO that provide a rich concurrency mechanism. Coroutines Actors Futures Scheduler. Coroutines. Coroutines are the foundation for concurrency within IO.

vera-bray
Download Presentation

IO Concurrency

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IO Concurrency Kurt Niemi CPSC 5135 Spring Semester 2011

  2. Main Components These are the major components in IO that provide a rich concurrency mechanism. • Coroutines • Actors • Futures • Scheduler

  3. Coroutines • Coroutinesare the foundation for concurrency within IO. • This is the mechanism in IO to allow for a process to voluntarily suspend and resume execution. • Coroutines can conceptually be thought of as a function that has multiple entry points • Calling yield within a coroutine suspends a process, allowing another one to execute

  4. Coroutines • Note: IO multitasking is different than the traditional pre-emptive multitasking found in Java and C-based languages. • In Java/C, the execution of a method may be interrupted at any point in time – requiring extra care to make code thread safe if multiple threads are accessing are manipulating the same object. • In IO, it is up to the programmer to call yield (at convenient/appropriate points). • Remember with greater power, comes greater responsibility.

  5. Actors • Actors are a mechanism of IO to avoid race conditions. • Actors can only change their own state • Actors can only access other actors via internal queues in IO. • Sending an asynchronous message to any object makes it an actor. • Adding @@ in front of a message is the IO syntax to make a message asynchronous.

  6. Futures • A future is a result object that is immediately returned from an asynchronous message call • This can be thought of as a placeholder for the final result. • If the value of a future is attempted to be accessed before the result is available, IO automatically blocks the current process until the result is available. • Futures also provide for automatic deadlock detection

  7. Futures • Messages can be fired asynchronously using both @ and @@ • Using @ returns a Future. • Using @@ returns nil and starts the message in it’s own thread.

  8. Scheduler • IO has a Scheduler object that is responsible for resuming coroutines that have yielded execution. • The Scheduler, like the IO language, is simple. A FIFO (First in-First Out) policy with no priorities is used.

  9. Putting it All Together • OK, enough talk. Show me the code. Let’s walk through an example application showing IO’s concurrency features

  10. Summary • IO has some very powerful concurrency features, and like the language itself it is simple to use. • Issues such as Race Conditions and Deadlock are automatically handled by the Actor and Futures in IO • IO multitasking/threading is different than Java / C-based languages. The application code determines when it is ready to yield to another thread.

  11. Resources • IO language documentation http://www.iolanguage.com/scm/io/docs/IoGuide.html • 7 languages in 7 weeks (IO section – Day 3) http://www.pragprog.com/titles/btlang/seven-languages-in-seven-weeks

More Related