poll wait阻塞 喚醒

2021-07-10 03:02:46 字數 1210 閱讀 5992

1. 應用阻塞

應用程式使用 select() 或 poll() 呼叫裝置驅動程式的 poll() 函式,該函式把輸入輸出復用處理的等待佇列追加到由核心管理的程序的 poll_table()上

#include 

static

inline

void poll_wait (struct file *filp, wait_queue_head_t *wait_address, poll_table *p);

filp:裝置檔案資訊的 struct file 結構體的指標引數 struct file *filp

p:追加到裝置驅動上的 poll_table結構體指標引數

2. 核心等待事件

/* 

* conditon:必須滿足,否則阻塞

* timeout和conditon相比,有更高優先順序

*/wait_event(wq, condition);

wait_event_timeout(wq, condition, timeout);

wait_event_interruptible(wq, condition) ;

wait_event_interruptible_timeout(wq, condition, timeout) ;

3. 喚醒等待佇列

//可喚醒處於task_interruptible和task_uninterruptible狀態的程序

#define wake_up(x) __wake_up(x, task_normal, 1, null)

//只能喚醒處於task_interruptible狀態的程序

#define wake_up_interruptible(x) __wake_up(x, task_interruptible, 1, null)

4. schedule_timeout

表示的程序睡眠直到時間超時,函式就會立即返回

5. 訊號

task_interruptible是可以被訊號和wake_up()喚醒的,當訊號到來時,程序會被設定為可執行

task_uninterruptible只能被wake_up()喚醒

程序的阻塞 喚醒 掛起 啟用

程序控制的一些概念 程序控制是程序管理中最基本的功能。建立 終止 可負責程序執行中的狀態轉換。程序控制一般是由os的核心中的原語來實現的。原語 primitive 是由若干條指令組成的,用於完成一定功能的乙個過程。它與一般過程的區別在於 它們是 原子操作 action operation 即不可分割...

AQS 執行緒 續集 喚醒 和 阻塞

接著 搶占式 共享 那裡,當 獲取鎖始終 失敗。獲取失敗,執行緒等待 具體後面介紹if shouldparkafte iledacquire p,node parkandcheckinterrupt interrupted true 在獲取同步狀態失敗後,執行緒並不是立馬進行阻塞,需要檢查該執行緒的...

如何喚醒socket被阻塞的函式

最近專案遇到乙個問題,程式退出的時候資源沒有正常釋放。經過除錯發現,原來是網路執行緒一直阻塞,導致一些必要的資源沒有被釋放,寫了幾個簡單的測試程式除錯了一下才明白,原來在linux下直接close socket的檔案描述符,並不會使程式中呼叫的一些阻塞式的socket函式 比如 read recvf...