Chapter 9:執行緒 === :::info 這是讀書筆記  作者:鄭鋼 出版社:佳魁資訊股份有限公司 出版日期:2017/05/31 ::: --- # 執行緒簡介 * 執行緒本質就是函數。 * 執行緒就是執行一段函數的載體。 * 執行緒有獨立的 register, stack. * 執行緒是排程的最小單元。 * Process = thread + resource * process 有自己的分頁,thread 沒有。 * PCB: process control block * User space thread vs. kernel space thread. # Kernel Thread * intr_stack: p.7-65 stack for main thread. * thread_stack: new thread ret 時使用的。 * main thread 只做 init_thread 沒有做 thread_create。 * 其他則是會 call thread_start: init_thread and thread_create。 * thread_create: esp = page base + PG_SIZE - intr_stack - thread_stack。 * running_thread: 利用當前的 esp 取得 pcb。 # Linked list 實作部分自行研究~ # 多執行緒排程 >[!Note] 實作 Round Robin 的排程器 ## Source Code https://github.com/yifengyou/os-elephant/tree/master/code/c09/c ## Result 可以設定 break point on switch_to 觀察 thread 切換。   預期會發生 GP 例外  ### 調整切換 thread 的頻率 > timer.c ``` #define IRQ0_FREQUENCY 1000 ``` > main.c ``` thread_start("k_thread_a", 4, k_thread_a, "argA "); thread_start("k_thread_b", 2, k_thread_b, "argB "); ``` > thread.c ``` init_thread(main_thread, "main", 8); ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up