简体   繁体   中英

How to implement asynchronous reading in go?

I study golang scheduler in linux. I think golang using multi-thread to implement goroutine , when some goroutine is blocked in I/O(just like reading a file), other thread go on processing another goroutine . But when there is lots of I/O,I don't think thread is enough, how golang deal with it ?

I read a article http://morsmachine.dk/netpoller , it says “Go gets around this problem by using the asynchronous interfaces that the OS provides, but blocking the goroutines that are performing I/O.” . Is it like the aio_read ? It is said that there is lots of bugs with the asynchronous interfaces . And I don't find it in the source code or I just miss it.

As we know , I understand we can use epoll to do asynchronous io for pipes and socket, but epoll can't be used to reading or writing of regular file. And nodejs use libeio to do this for regular file. I want to know how golang do it in runtime.

Go doesn't use anything special for file I/O yet. It just creates a new thread (so that there are always GOMAXPROCS threads available for goroutines) and blocks on the operation. I think there already was some discussion going on about using AIO on the mailing list, but there were many problems at that time. The golang-nuts mailing list is probably a better place for this kind of questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM