Computer Science 312 Concurrent Programming I Processes and Messages 1.

Slides:



Advertisements
Similar presentations
Processes Management.
Advertisements

COMMUNICATING SEQUENTIAL PROCESSES C. A. R. Hoare The Queen’s University Belfast, North Ireland.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.
28.2 Functionality Application Software Provides Applications supply the high-level services that user access, and determine how users perceive the capabilities.
Computer Systems/Operating Systems - Class 8
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Distributed systems Programming with threads. Reviews on OS concepts Each process occupies a single address space.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Erlang concurrency. Where were we? Finished talking about sequential Erlang Left with two questions  retry – not an issue; I mis-read the statement in.
Concurrency CS 510: Programming Languages David Walker.
Lecture 19 Distributed Programming (Ch. 10) Other message-passing programming models  Channels vs mailboxes  Synchronous vs asynchronous.
Sequence Diagrams By Zvika Gutterman Adam Carmi. Sequence Diagrams2 Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control.
ITERATIVE COMPUTATIONS CONCURRENCY ID1218 Lecture Christian Schulte Software and Computer Systems School of Information and.
1 Chapter 4 Threads Threads: Resource ownership and execution.
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
Chapter 4.1 Interprocess Communication And Coordination By Shruti Poundarik.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
Multicore Computing Using Erlang Art Gittleman California State University Long Beach
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
1 Lecture 5 (part2) : “Interprocess communication” n reasons for process cooperation n types of message passing n direct and indirect message passing n.
 Remote Procedure Call (RPC) is a high-level model for client-sever communication.  It provides the programmers with a familiar mechanism for building.
Networks and Client/Server Applications Handling Multiple Clients Concurrently.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Shuman Guo CSc 8320 Advanced Operating Systems
Maria Christakis National Technical University of Athens, Greece Joint work with Kostis Sagonas Detection of Asynchronous Message Passing Errors Using.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Remote Procedure Call Andy Wang Operating Systems COP 4610 / CGS 5765.
Erlang Noah Dietrich Chris Ruffalo.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
CS603 Basics of underlying platforms January 9, 2002.
Mark Stanovich Operating Systems COP Primitives to Build Distributed Applications send and receive Used to synchronize cooperating processes running.
LOGO Erlang 11 ACM 王浩然. Company Logo concurrency  in real world  in computer.
Remote Procedure Call and Serialization BY: AARON MCKAY.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Implementing Remote Procedure Call Landon Cox February 12, 2016.
Channels. Models for Communications Synchronous communications – E.g. Telephone call Asynchronous communications – E.g. .
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
Message passing model. buffer producerconsumer PRODUCER-CONSUMER PROBLEM.
Communication in Distributed Systems. . The single most important difference between a distributed system and a uniprocessor system is the interprocess.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Remote Procedure Calls
Interprocess Communication Race Conditions
Threaded Programming in Python
Processes and threads.
Chapter 3: Process Concept
Chapter 3: Windows7 Part 4.
Programming Models for Distributed Application
Concurrency: Mutual Exclusion and Synchronization
Networks and Client/Server Applications
Inter Process Communication (IPC)
Sarah Diesburg Operating Systems COP 4610
Process-to-Process Delivery:
Erlang 3 Concurrency 8-Dec-18.
Basic Syntax and Semantics
Issues in Client/Server Programming
Threads Chapter 4.
Channels.
Multithreaded Programming
Subject : T0152 – Programming Language Concept
Channels.
Channels.
Process-to-Process Delivery: UDP, TCP
Presentation transcript:

Computer Science 312 Concurrent Programming I Processes and Messages 1

Mapping 1> lists:map(math:sqrt, [4, 16, 25]). ** exception error: bad function sqrt in function lists:map/2 (lists.erl, line 1224) 2> lists:map(fun(X) -> math:sqrt(X) end, [4, 16, 25]). [2.0, 4.0, 5.0] Must create a fun to pass a function as data, but syntax is complicated

Mapping Can use a function reference instead! 1> lists:map(math:sqrt, [4, 16, 25]). ** exception error: bad function sqrt in function lists:map/2 (lists.erl, line 1224) 2> lists:map(fun(X) -> math:sqrt(X) end, [4, 16, 25]). [2.0, 4.0, 5.0] Can use a function reference instead! 3> lists:map(fun math:sqrt/1, [4, 16, 25]). [2.0, 4.0, 5.0]

Concurrency-Oriented Programming Modern programs execute in multiple processes, which may run on separate processors, either within a single computer (multicore) or on different computers across a network The discipline of designing and implementing such programs is called concurrency-oriented programming

Shared Memory vs Message-Passing Processes can share memory, but then must be regulated to avoid synchronization problems (deadlock, lockout, race conditions) Alternatively, each process gets its own private memory, and they communicate by sending and receiving messages Erlang combines the functional model with message passing

Just Three Concurrency Primitives Pid = spawn(Fun) – Creates a new process that executes the function Fun. Pid can then be used to send messages to the process. Pid ! Message – Sends Message to the process Pid. The sender then continues execution. receive ... end – Receives a message. See next slide . . .

The Basic Details of receive Pattern1 [Guard1] -> Expressions1; Pattern2 [Guard2] -> Expressions2; . . . after Time -> AfterExpressions end When a message comes in, receive executes the expression for the first pattern that the message matches. If no match is found, the message goes on a queue and receive waits for another message. The timer is optional.

Where Do Messages Come From? Senders Mailbox Receiver Messages Save queue Messages from senders are placed in the receiver’s mailbox. The receiver removes these and handles them in sequence.

Where Do Messages Come From? Senders Mailbox Receiver Messages Save queue If no messages match, they remain on the save queue and the receiver suspends execution.

Where Do Messages Come From? Senders Mailbox Receiver Messages Save queue If a new message arrives at an empty mailbox, the receiver resumes execution but the saved messages remain on the save queue.

Where Do Messages Come From? Senders Mailbox Receiver Messages Save queue If a message matches, the messages on the save queue are placed back in the mailbox and the timer (if set) is cleared.

Where Do Messages Come From? Senders Mailbox Receiver Messages Save queue If the timer elapses during the wait for a message, its expression is run and the messages on the save queue are moved back to the mailbox.

A Simple Greeting Server % greeting_server0.erl -module(greeting_server0). -export([loop/0]). loop() -> receive hello -> io:format("Hello!~n"), loop(); goodbye -> io:format("Goodbye!~n"), Other -> io:format("Message not recognized: ~p ~n", [Other]), loop() end.

Spawn and Send Messages 1> Pid = spawn(fun greeting_server:loop/0). <0.42.0> 2> Pid ! hello. Hello! hello 3> Pid ! goodbye. Goodbye! goodbye 4> Pid ! ken. Message not recognized: ken ken

A Simple Greeting Server % greeting_server0.erl -module(greeting_server0). -export([loop/0]). loop() -> receive hello -> io:format("Hello!~n"), loop(); goodbye -> io:format("Goodbye!~n"), Other -> io:format("Message not recognized: ~p ~n", [Other]), loop() end. Because the server loop is tail-recursive, it can in principle run forever.

Client/Server Programming Many Clients Requests Server Replies The clients and servers are processes, running on the same computer or different computers A server handles a client’s request and replies to the client with the result.

Provide a Return Address for the Reply In the client’s code: Server ! {self(), hello}. self() returns the ID of the currently executing process In the server’s code: loop() -> receive {Client, hello} -> Client ! "Hello!~n", loop(); . . .

For next time Remote procedure call