阻塞读取和非阻塞读取有什么区别? [英] What is the difference between a blocking and non-blocking read?

查看:563
本文介绍了阻塞读取和非阻塞读取有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上面的问题中添加了一个等待/不等待指示符的概念,作为TCP/IP或UDP环境中ReadMessage函数的参数.

Add to the above question the concept of a wait/no wait indicator as a parameter to a ReadMessage function in a TCP/IP or UDP environment.

第三方功能描述指出:

此函数用于从队列读取消息,该队列由先前的registerforinput调用定义.输入等待/不等待指示符将确定此功能是否在指定的队列上阻塞,等待数据放入队列中.如果指定了nowait选项并且没有可用数据,则将NULL指针返回给调用方.当数据可用时,此函数将返回一个指针,该指针指向从队列中读取的数据.

This function is used to read a message from a queue which was defined by a previous registerforinput call. The input wait/no wait indicator will determine if this function will block on the queue specified, waiting for the data to be placed on the queue. If the nowait option is specified and no data is available a NULL pointer will be returned to the caller. When data available this function will return a pointer to the data read from the queue.

函数阻塞或不阻塞意味着什么?

What does it mean for a function to be blocking or non-blocking?

推荐答案

阻塞意味​​着您的代码(在该线程中)的执行将在调用过程中停止.本质上,直到阻塞操作完成,函数调用才会返回.

Blocking means that execution of your code (in that thread) will stop for the duration of the call. Essentially, the function call will not return until the blocking operation is complete.

阻塞读取将等待,直到有可用数据(或超时(如果有的话)到期),然后从函数调用返回.非阻塞读取将(或至少应该)始终立即返回,但如果当前没有可用数据,则可能不会返回任何数据.

A blocking read will wait until there is data available (or a timeout, if any, expires), and then returns from the function call. A non-blocking read will (or at least should) always return immediately, but it might not return any data, if none is available at the moment.

这篇关于阻塞读取和非阻塞读取有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆