阻塞与非阻塞知识点总结

current代表当前进程,源代码如下:

static inline struct task_struct *get_current()

#define current (get_current())


实现阻塞方法:



实现阻塞: 默认情况,大部分的函数默认都是阻塞
 scanf()-- fgets()
 accept(); read/recv/recvfrom

0---需要一个等待队列头
struct __wait_queue_head wait_queue_head_t;
init_waitqueue_head(struct wait_queue_head_t *q)


// 参数1---表示等待队列头
// 参数2---表示一个条件--如果为假,就在此休眠,如果为真,就不休眠
1,根据条件可以让进程进入到休眠状态

wait_event_interruptible(struct wait_queue_head_t wq, int condition)

set_current_state(TASK_INTERRUPTIBLE);     等同

add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait);  

schedule(void);

 三个函数等同于: wait_event_interruptible(queue,condition);



2, 资源可达的时候需要唤醒
wake_up_interruptible(wait_queue_head_t *q)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值