tailieunhanh - Concepts, Techniques, and Models of Computer Programming - Chapter 5
Message-Passing Concurrency Trong chương cuối cùng, chúng ta thấy làm thế nào để lập trình với các đối tượng dòng, mà là cả hai khai báo và đồng thời. Tuy nhiên, nó có giới hạn mà nó không thể xử lý nondeterminism quan sát được. Ví dụ, chúng tôi đã viết một mô phỏng logic kỹ thuật số, trong đó mỗi đối tượng dòng biết chính xác đối tượng sẽ gửi tin nhắn tiếp theo. Chúng ta không thể một chương trình máy chủ máy khách / máy chủ không biết mà khách hàng sẽ gửi tin nhắn. | Chapter 5 Message-Passing Concurrency Only then did Atreyu notice that the monster was not a single solid body but was made up of innumerable small steel-blue insects which buzzed like angry hornets. It was their compact swarm that kept taking different shapes. - The Neverending Story Michael Ende 1929-1995 In the last chapter we saw how to program with stream objects which is both declarative and concurrent. But it has the limitation that it cannot handle observable nondeterminism. For example we wrote a digital logic simulator in which each stream object knows exactly which object will send it the next message. We cannot program a client server where the server does not know which client will send it the next message. We can remove this limitation by extending the model with an asynchronous communication channel. Then any client can send messages to the channel and the server can read them from the channel. We use a simple kind of channel called a port that has an associated stream. Sending a message to the port causes the message to appear on the port s stream. The extended model is called the message-passing concurrent model. Since this model is nondeterministic it is no longer declarative. A client server program can give different results on different executions because the order of client sends is not determined. A useful programming style for this model is to associate a port to each stream object. The object reads all its messages from the port and sends messages to other stream objects through their ports. This style keeps most of the advantages of the declarative model. Each stream object is defined by a recursive procedure that is declarative. Another programming style is to use the model directly programming with ports dataflow variables threads and procedures. This style can be useful for building concurrency abstractions but it is not recommended for large programs because it is harder to reason about. Copyright 2001-3 by P. Van Roy and S. Haridi. .
đang nạp các trang xem trước