我(初学者)对阻塞和非阻塞io的理解正确吗? [英] Do my (beginner) understanding of blocking and non blocking io is correct?

查看:86
本文介绍了我(初学者)对阻塞和非阻塞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.我欢迎阅读和介绍,例如: http://www.paperplanes.de/2011 /4/25/eventmachine-how-does-it-work.html http://www.kegel.com/c10k.html

PS. I would welcome readings and presentations, like: http://www.paperplanes.de/2011/4/25/eventmachine-how-does-it-work.html http://www.kegel.com/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的理解正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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