我(初学者)对阻塞和非阻塞io的理解正确吗?

编程入门 行业动态 更新时间:2024-10-24 16:31:33
本文介绍了我(初学者)对阻塞和非阻塞io的理解正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

现在,我对并发性和并行性进行了大量研究.你能告诉我我是否理解正确(在操作系统水平上):

Right now I do a lot of research about concurrency and parallelism. Could you tell me if I understand correctly (on os level):

阻止io:

当我明确等待连接时(即在Ruby中)

When I explicitly wait for connection (ie. in Ruby:)

conn = socket.accept

所以我的线程被阻塞,直到我得到一些东西,对吧?

So my thread is blocked until I get something to socket, right?

(而且我知道我在某个循环中将套接字池化为接受数据,对吗?)

(And I understand that I am pooling socket in some loop in accept for data, right?)

非阻塞:

我有一个线程不时询问所有注册的fd(文件描述符)是否有我需要的东西.但是也有不要打电话给我们,我们会打电话给您"的规则,但是它在ios级别上是如何工作的(在事件机或节点之类的库中,它是通过回调(?)完成的)

I have thread that is asking from time to time all registered fd (filedescriptors) if they have something I need. But there is also 'dont call us, we will call you' rule, but how it is working on ios level (on libraries like eventmachine or node it is done by callbacks (?))

PS.我欢迎阅读和介绍,例如: www.paperplanes.de/2011 /4/25/eventmachine-how-does-it-work.html www.kegel/c10k.html

PS. I would welcome readings and presentations, like: www.paperplanes.de/2011/4/25/eventmachine-how-does-it-work.html www.kegel/c10k.html

推荐答案

阻止io:

Blocking io:

当我明确等待连接时(即在Ruby中)

When I explicitly wait for connection (ie. in Ruby:)

conn = socket.accept

conn = socket.accept

所以我的线程被阻塞,直到我得到一些东西,对吧?

So my thread is blocked until I get something to socket, right?

对.

(而且我知道我在某个循环中将套接字池化为接受数据,对吗?)

(And I understand that I am pooling socket in some loop in accept for data, right?)

错了.你被封锁了.时期.发生相关事件时,操作系统将唤醒您.

Wrong. You are blocked. Period. The operating system will wake you up when something relevant happens.

非阻塞:

我有一个线程不时询问所有注册的fd(文件描述符)是否有我需要的东西.但是也有不要打电话给我们,我们会打电话给您"的规则,但是它在ios级别上是如何工作的(在事件机或节点之类的库中,它是通过回调(?)完成的)

I have thread that is asking from time to time all registered fd (filedescriptors) if they have something I need. But there is also 'dont call us, we will call you' rule, but how it is working on ios level (on libraries like eventmachine or node it is done by callbacks (?))

您刚才描述的包括回调的是异步" I/O.

What you have just described including the callbacks is 'asynchronous' I/O.

非阻塞I/O只是意味着调用不会阻塞,例如如果您调用read()并且那里没有数据,则什么也不会发生.何时呼叫取决于您,但是select()/poll()/epoll()会协助您进行呼叫,这会阻塞直到套接字上发生各种事件.

Non-blocking I/O just means that the calls don't block, so e.g. if you call read() and there is no data already there, nothing happens. When to call the calls is up to you but it is assisted by select()/poll()/epoll(), which block until various events have occurred on the socket(s).

更多推荐

我(初学者)对阻塞和非阻塞io的理解正确吗?

本文发布于:2023-11-25 17:53:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630737.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初学者   正确   io

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!