Seven Concurrency Models in Seven Weeks (Paul Butcher, 2014) 독후감 - 복습하고 교양쌓고 배우기
두 번째로 읽은 Seven Weeks 시리즈 책이다. ’Seven Databases in Seven Weeks (Luc Perkins et al., 2018)’ 책을 재미있게 읽어서 블랙프라이데이 할인을 받아 이 책을 사서 읽었다.
간단한 내용 소개
Threads and Locks, Functional Programming, Clojure, Elixir, Go Channel, OpenCL, Hadoop의 Concurrency(동시성) 모델을 소개한다. 함수형 프로그래밍과 Elixir 챕터는 편하게 읽었다. 저자가 Clojure를 엄청 좋아하는 것 같다. Go Channel을 Go 언어가 아니라 Clojure로 설명한다.
재미있었던 CSP(communicating sequential processes)
Threads and Locks은 복습한다는 기분으로 읽었고 OpenCL과 Hadoop은 교양 삼아 읽었다. 제일 재미있게 읽었던 챕터는 CSP(communicating sequential processes) 설명 챕터였다.
A program using the communicating sequential processes model similarly consists of independent, concurrently executing entities that communicate by sending each other messages. The difference is one of emphasis - instead of focusing on the entities sending the messages, CSP focuses on the channels over which they are sent. Channels are first class- instead of each process being tightly coupled to a single mailbox, channels can be independently created, written to, read from, and passed between processes.
통신 순차 프로세스 모델을 사용하는 프로그램은 마찬가지로 독립적이고 동시에 실행되는 엔티티들로 구성되며, 이들은 서로 메시지를 전송하여 통신합니다. 차이점은 강조점의 차이입니다 - 메시지를 전송하는 엔티티에 초점을 맞추는 대신, CSP는 메시지가 전송되는 채널에 초점을 맞춥니다. 채널은 첫 번째 클래스입니다 - 각 프로세스가 단일 메일박스와 밀접하게 연결되는 대신, 채널은 독립적으로 생성되고, 쓰이며, 읽히며, 프로세스 간에 전달될 수 있습니다.
Actor Model을 사용하는 Erlang과 Elixir에서는 채널이라고 부를 수 있는 Mailbox가 Actor과 강결합이 되어 있다. 하지만 CSP에서는 Go channel 처럼 채널 자체를 독립적으로 쓸 수 있다. 채널이 일급 객체다.
(defn start []
(go
(let [wizard (dom/getElement "wizard")
step1 (dom/getElement "step1")
step2 (dom/getElement "step2")
step3 (dom/getElement "step3")
next-button (dom/getElement "next")
next-clicks (get-events next-button "click")]
(show step1)
(<! next-clicks)
(hide step1)
(show step2)
(<! next-clicks)
(set-value next-button "Finish")
(hide step2)
(show step3)
(<! next-clicks)
(.submit wizard))))
(set! (.-onload js/window) start)
채널로 콜백을 풀어내는 코드가 인상적이었다.
마치며
모아서 정리하면 얽힌 개념이 명료하게 정리되는 기분을 느끼곤 한다. 그런 즐거움을 주는 책이다.