frank.lin
frank.lin

Reputation: 1694

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.

Upvotes: 1

Views: 4211

Answers (1)

randomgopher
randomgopher

Reputation: 21

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.

Upvotes: 2

Related Questions