目的: 檢驗學員對並行和多執行緒程式設計的認知
1
考慮我們嘗試建構 lock-free 的 MPMC broadcast queue、依循 Publish–subscribe 模式,程式碼可見 broadcast,其中 pool.[ch]
是 lock-free memory pool。
編譯方式:
$ gcc -Wall -O2 -D_GNU_SOURCE \
-o stress \
stress.c \
broadcast.c \
pool.c \
-lpthread
參考執行輸出:
Test: 1pub0sub
Pub Thread 0 | n_msgs: 100000 n_drops: 0 | 169 ns/msg
Test: 2pub0sub
Pub Thread 0 | n_msgs: 100000 n_drops: 0 | 519 ns/msg
Pub Thread 1 | n_msgs: 100000 n_drops: 0 | 416 ns/msg
Test: 4pub0sub
Pub Thread 0 | n_msgs: 100000 n_drops: 0 | 945 ns/msg
Pub Thread 1 | n_msgs: 100000 n_drops: 0 | 965 ns/msg
Pub Thread 2 | n_msgs: 100000 n_drops: 0 | 952 ns/msg
Pub Thread 3 | n_msgs: 100000 n_drops: 0 | 967 ns/msg
Test: 4pub0sub
Pub Thread 0 | n_msgs: 100000 n_drops: 0 | 2800 ns/msg
Pub Thread 1 | n_msgs: 100000 n_drops: 0 | 3015 ns/msg
Pub Thread 2 | n_msgs: 100000 n_drops: 0 | 3065 ns/msg
Pub Thread 3 | n_msgs: 100000 n_drops: 0 | 3060 ns/msg
Pub Thread 4 | n_msgs: 100000 n_drops: 0 | 3062 ns/msg
Pub Thread 5 | n_msgs: 100000 n_drops: 0 | 3033 ns/msg
Pub Thread 6 | n_msgs: 100000 n_drops: 0 | 3021 ns/msg
Pub Thread 7 | n_msgs: 100000 n_drops: 0 | 3043 ns/msg
AAAA, BBBB, CCCC, DDDD, EEEE, FFFF 皆為變數名稱
前一章所研讀的 patches 最終並未正式合併到 kernel 中。維護者 Peter Zijlstra 針對此做了修正與調整,重新釋出了進階的改動 [RFC][PATCH 00/10] sched/fair: Complete EEVDF。在此系列內容中,除了原本對 time slice/request size 的支援,Peter 還新增 delayed-dequeue 機制以彌補原始論文在 EEVDF 上的缺陷。這些改動將成為補足 EEVDF 的最後一塊拼圖。而本節將針對這一系列內容進行探討。
Sep 6, 2025無論是作業系統核心、C 語言函式庫內部、程式開發框架,到應用程式,都不難見到 linked list 的身影,包含多種針對效能和安全議題所做的 linked list 變形,又還要考慮到應用程式的泛用性 (generic programming),是很好的進階題材。
Sep 4, 2025資料整理: jserv
Aug 31, 2025本講座帶著學員重新探索函式呼叫背後的原理,從程式語言和計算機結構的發展簡史談起,讓學員自電腦軟硬體演化過程去掌握 calling convention 的考量,伴隨著 stack 和 heap 的操作,再探討 C 程式如何處理函式呼叫、跨越函式間的跳躍 (如 setjmp 和 longjmp),再來思索資訊安全和執行效率的議題。
Aug 28, 2025or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up