Stanford CS 94SI - Concurrent Paradigms (61 pages)

Previewing pages 1, 2, 3, 4, 28, 29, 30, 31, 58, 59, 60, 61 of 61 page document View the full content.
View Full Document

Concurrent Paradigms



Previewing pages 1, 2, 3, 4, 28, 29, 30, 31, 58, 59, 60, 61 of actual document.

View the full content.
View Full Document
View Full Document

Concurrent Paradigms

25 views


Pages:
61
School:
Stanford University
Course:
Cs 94si - An Interdisciplinary Survey
An Interdisciplinary Survey Documents

Unformatted text preview:

Concurrent Paradigms Jorge Ortiz CS94SI Concurrency is hard Paradigm Shared Memory Locks Memory Execution Thread Memory Threads Threads Problems Problem 1 Race conditions Shared Mutable State Threads Threads Race condition Segfault Segfault Checking whether build environment is sane build environment is grinning and holding a spatula Guess not Fix 1 Locks Shared Mutable State Threads Lock Threads Race condition Shared Mutable State Threads Coarse lock Threads Race condition Problem 2 Blocking contention Shared Mutable State Threads Fine grained locks Threads Race condition Problem 3 Overhead Solutions 2 3 Nothing really It s a trade off Problem 4 Deadlock Shared Mutable State Threads Threads Deadlock Solution 4 Rigorous adherence to complicated lock order Problem 5 Doesn t compose Problem 6 Hard to debug Languages Well very popular Paradigm Actors Actor Principles Actor Principles No shared mutable state Actor Principles No shared mutable state All mutable state is private Actor Principles No shared mutable state All mutable state is private All shared state is immutable Actor Principles No shared mutable state All mutable state is private All shared state is immutable Communicate via immutable asynchronous message passing Actor Principles No shared mutable state All mutable state is private All shared state is immutable Communicate via immutable asynchronous message passing Messages threads are extremely lightweight Actor Components Actors Very lightweight threads Messages Immutable hence lightweight Mailboxes Asynchronous non blocking queues Actors Private Mutable State Mailboxes Messages In Erlang start loop 0 loop Sum receive increment Count loop Sum Count reset loop 0 counter Pid Pid counter Sum loop Sum end In Scala We need to define our messages first case case case case class Increment count Int object Reset class ReportTotal a Actor class ReportingTotal sum Int In Scala object Counter extends Actor var sum 0 def act while true receive case Increment cnt sum



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Concurrent Paradigms and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Concurrent Paradigms and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?