A Swing programmer deals with the following kinds of threads: ● Initial threads, the threads that execute initial application code. ● The event dispatch thread, where all event-handling code is executed. Most code that interacts with the Swing framework must also execute on this thread. ● Worker threads, also known as background threads, where time-consuming background tasks are executed. スレッド使用例 Swing guide UI framework https://docs.oracle.com/javase/tutorial/uiswing /concurrency/index.html
thread interference (非atomic処理) class Counter { private int c = 0; public void increment() { c++; } public void decrement() { c--; } public int value() { return c; } }
synchronized class Counter { private int c = 0; public synchronized void increment() { c++; } public synchronized void decrement() { c--; } public int value() { return c; } }
volatile “write to a volatile variable establishes a happens-before relationship with subsequent reads of that same variable” volatile int counter = 0;
CPUとキャッシュ Stack Exchange - Where exactly L1, L2 and L3 Caches located in computer? https://superuser.com/questions/1961 43/where-exactly-l1-l2-and-l3-caches-loc ated-in-computer キャッシュは「スレッド ごとのメモリ空間」に関 わる -> data race -> happens-before
CPUとキャッシュ Stack Exchange - Where exactly L1, L2 and L3 Caches located in computer? https://superuser.com/questions/1961 43/where-exactly-l1-l2-and-l3-caches-loc ated-in-computer キャッシュは「スレッド ごとのメモリ空間」に関 わる -> data race -> happens-before data race (memory-consistency error)
main() function funC(c) { … //make an ajax call } function funcB(b) { return funcC(b); } function funcA(a) { return funcB(a); } funcA(“my user data string”); call stack event loop
main() function funC(c) { … //make an ajax call } function funcB(b) { return funcC(c); } function funcA(a) { return funcB(a); } funcA(“my user data string”); call stack event loop
function funC(c) { … //make an ajax call } function funcB(b) { return funcC(c); } function funcA(a) { return funcB(a); } funcA(“my user data string”); event loop ajax コールバック タスクキュー
Akka actorコードサンプル actor ! message class MyActor extends Actor { var state = ... def receive = { case MessageTypeX => ... case MessageTypeY => ... case MessageTypeZ => ... } }
文献 Our World in Data https://ourworldindata.org/internet 世界のインターネットユーザ数の統計。 Statista https://www.statista.com/statistics/... 年間スマートフォン出荷台数の統計。 https://twitter.com/csgillespie/status/… CPUクロック周波数に関するグラフ付きツイート。
OSとCPU Systems Performance https://www.amazon.com/gp… Netflixのパフォーマンス分析エンジニアBrendan Gregg氏に よる著書。CPUとスレッドについての章がある。 Brendan Gregg’s Home page http://www.brendangregg.com/overview.html Brendan Gregg氏の著書にも関わる様々な情報がある See How a CPU works https://youtu.be/cNN_tTXABUA Scott CPUという教育用の仮想的なCPUを題材に動画で解説 している。
AjaxとGoogle Maps YouTube: Screen record of Google Maps in 2005 https://youtu.be/PDG6tELjCOE 一般ユーザによる録画と思われる。 YouTube: What the heck is the event loop anyway? JSConf https://youtu.be/8aGhZQkoFbQ アニメーションを駆使したevent loop解説。100万再生以上。
Inside NGINX: How We Designed for Performance & Scale https://www.nginx.com/blog/... nginx公式のアーキテクチャ解説。 MDN web docs: Concurrency model and Event Loop https://developer.mozilla.org/en-US/docs/... MozillaによるEvent Loop解説 JavaScript Promiseの本 https://azu.github.io/promises-book/ JavaScriptを中心に著名なエンジニアであるazu氏が書いた Promiseおよびasync/awaitを解説したウェブ上の本 JavaScript promise, async/await