Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming_in_Scala,_2nd_edition.pdf
Скачиваний:
25
Добавлен:
24.03.2015
Размер:
22.09 Mб
Скачать

Section 32.7

Chapter 32 · Actors and Concurrency

757

signal Wire(ain) changed to true signal Wire(sout) changed to false signal Wire(bin) changed to false

Advancing

to time

3

Advancing

to time

4

Advancing

to time

5

Advancing

to time

6

Advancing

to time

7

Advancing

to time

8

Advancing

to time

9

Advancing

to time

10

signal Wire(cout)

changed to true

Advancing

to time

11

Advancing

to time

12

Advancing

to time

13

Advancing

to time

14

Advancing

to time

15

Advancing

to time

16

Advancing

to time

17

Advancing

to time

18

signal Wire(sout)

changed to true

Advancing

to time

19

Advancing

to time

20

Advancing

to time

21

signal Wire(sout)

changed to false

** Agenda

empty.

Clock exiting at time 21.

As expected, with inputs of 1, 0, and 1 (true, false and true), the outputs are a carry of 1 and sum of 0 (cout is true, and sout is false).

32.7 Conclusion

Concurrent programming gives you great power. It lets you simplify your code, and it lets you take advantage of multiple processors. It is therefore unfortunate that the most widely used concurrency primitives, threads, locks, and monitors, are such a minefield of deadlocks and race conditions.

The actors style provides a way out of the minefield, letting you write concurrent programs without having such a great risk of deadlocks and race

Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Section 32.7

Chapter 32 · Actors and Concurrency

758

conditions. This chapter has introduced several fundamental constructs for working with actors in Scala, including how to create actors, how to send and receive messages, and how to conserve threads with react, among other nuts and bolts. It then showed you how to use these constructs as part of a general actors style.

Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]