Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Parallel/Concurrent

 Parallel/Concurrent

is Parallel/Concurrent programming hard, if so, what can we do ?

lenage

May 13, 2015
Tweet

Other Decks in Programming

Transcript

  1. Concurrency is about dealing with lots of things at once.

    Parallelism is about doing lots of things at once. “ - Rob Pike
  2. What Makes Parallel Programming Hard? • Work Partitioning • Parallel

    Access Control • Resource Partitioning and Replication • Interacting with Hardware
  3. Solution: if there are 5 forks, only 4 Rons should

    be allowed at the table. We’ll have a waiter control access to the table.
  4. 4. When a Ron needs a fork, he asks his

    neighbor for his fork. When his neighbor gets the request: • if his fork is clean, he keep it • if his fork is dirty, he cleans it and sends it over
  5. • Actors never share state so they never need to

    compete for locks for access to shared data • Actors are never shared between threads, so only one thread ever accesses the actor’s state • When you pass a message to an actor, it goes in his mailbox. The actor reads messages from his mailbox and does those tasks one at a time
  6. Celluloid is a concurrent object oriented programming framework for Ruby

    which lets you build multithreaded programs out of concurrent objects just as easily as you build sequential programs out of regular objects “
  7. • Actors are computational entities that can receive messages •

    Each actor has a unique address • If you know an actor's address, you can send it messages • Actors can create new actors
  8. • Vars - global • Atoms - synchronous • Agents

    - asynchronous • Refs - transaction
  9. Locks • Available in most languages • Give you fine-grained

    control over your code • Complicated to use. Your code will have subtle deadlock / starvation issues
  10. Actors • No shared state, so writing thread-safe is a

    breeze • No locks, so no deadlock unless your actors block • All your code needs to use actors and message passing, so you may need to restructure your code
  11. STM • Very easy to use, don’t need to restructure

    code • No locks, so no deadlock • Good performance (threads spend less time idling)
  12. RCU Fundamentals • Publish-Subscribe Mechanism (for insertion) • Wait For

    Pre-Existing RCU Readers to Complete (for deletion) • Maintain Multiple Versions of Recently Updated Objects (for readers)