COP 4020 Lecture -*- Outline -*- * The Data-Driven Concurrent Model (Ch 4) Based on Peter van Roy and Seif Haridi's book, "Concepts, Techniques, and Models of Computer Programming" (MIT Press, 2004), where all references that are not otherwise attributed are found. ** self-test ------------------------------------------ SELF-TEST FOR CHAPTER 4 Motivation [EvaluateModels] Why is concurrency useful? Model [UseModels] What new features are added to the declarative model to support concurrency? Threads [Concepts] What does a thread do? Threads [MapToLanguages] How would you program the equivalent of threads in Java? C++? C? Usage [EvaluateModels] Why is this kind of concurrency, without mutable state (cells), simple to use? Threads [Concepts] What's the difference between thread and a process? Interleaving [Concepts] What is interleaving? What is the causal order? Causal order [Concepts] In the following, what orders of steps follow the causal order? local A B in thread {Browse A} end thread {Browse B} end thread A=3 end thread B=A+2 end end Observable nondeterminism [Concepts] What is a nondeterministic execuation? What is observable nondeterminism? Exceptions [Concepts] [UseModels] What happens when there is an unhandled exception in a thread? Termination [Concepts] What is partial termination? Logical equivalence [Concepts] What does it mean for two stores to be logically equivalent? Declarative Concurrency [Concepts] What is the formal definition of declarative concurrency? Failures [Concepts] Are failures declarative? Dataflow [UseModels] How do dataflow variables help with programming with threads? Streams [Concepts] [UseModels] What is a stream? How would it be implemented in Oz? Streams [MapToLanguages] How would you implement a stream in Java? Producer/Consumer programming [UseModels] What ways are there to program with a producer-consumer architecture? What techniques are there for doing flow control in a stream-based system? How are these techniques programmed? Bounded Buffer [UseModels] How does a bounded buffer help with flow control? How is it implemented in Oz? Bounded Buffer [MapToLanguages] How could you implement a bounded buffer in Java? Architecture [UseModels] Can streams only be used in pipelines? How do you prevent deadlocks from feedback in a stream-based system? Programming patterns [UseModels] [EvaluateModels] [MapToLanguages] How do you let the language determine the order of calculations? Why are coroutines hard to use? How can one thread wait for another in Oz? In Java? How do you write barrier synchronization? Lazy execution [Concepts] [UseModels] [EvaluateModels] [MapToLanguages] What is lazy execution? What features of Oz does it rely on? How would you simulate this in C++? Why is it useful? Is it independent of concurrency? Model of lazy execution [Concepts] What was needed in the formal model to have lazy execution? What is ByNeed's semantics like, if you ignore scheduling of when it runs? What is a need (what activates triggers)? Model of ByNeed [MapToLanguages] How would you program something like ByNeed in Java? Lazy sugar [Concepts] [UseModels] How is the lazy modifier on a function translated into ByNeed? Needs [Concepts] What operations in Oz determine when a by-need suspension is needed? Laziness, dataflow and concurrency [EvaluateModels] Does the combination of laziness and dataflow require concurrency? Lazy streams [EvaluateModels] What are the advantages to using lazy functions to program stream-based computation vs. explicitly programmed triggers? Lazy and language design [EvaluateModels] Why isn't lazy the default for functions? Bounded buffers [Concepts] [EvaluateModels] In what sense is using a bounded buffer a compromise between the data-driven and demand-driven models? Soft real time [Concepts] What is soft real-time programming? What operations are useful for it? NewTicker [UseModels] Write NewTicker such that {NewTicker} returns a stream that grows by 1 element per second. Haskell [Concepts] [MapToLanguages] What are the interesting features of Haskell? How does it differ from Oz? Haskell types [Concepts] [MapToLanguages] What kinds of types does Haskell support? What is the notation for each type? What is a monomorphic type? What is a polymorphic type? Give an example of each. Type inference [Concepts] [MapToLanguages] How does type inference work? Type classes [Concepts] [MapToLanguages] What is the difference between parametric and ad hoc polymorphism? How do type classes relate to object-oriented programming? How are they different? Utility of the model [EvaluateModels] What are the advantages of declarative programming? Can we do everything efficiently with the declarative model? What can't be done efficiently? What problems are hard to modularize in the declarative model? Is the real world declarative? Using several models [EvaluateModels] How can you use several computational models in the same program? Exceptions [Concepts] [EvaluateModels] Is the declarative model with exceptions still declarative? What happens if the execution of a by-need trigger cannot complete normally? Language Design [EvaluateModels] Should an imperative language like Java or C++ be lazy by default? Should a declarative language be lazy by default? Reduction order [Concepts] What is normal order? How does it differ from applicative order reduction? Dataflow variables [Concepts] [MapToLanguages] How is a dataflow variable like a communication channel? What are dataflow variables good for? ------------------------------------------