B
B
beduin012017-02-04 13:44:28
go
beduin01, 2017-02-04 13:44:28

How do goroutines work in Go?

1. Do I understand correctly that a goroutine performs some elementary operation (or a block of code), after which the yield function is called and the next goroutine starts executing?
2. Do I understand correctly that any blocking operation (up to memory operation) after its start calls yield to switch to another goroutine?
3. Do I understand correctly that all blocking operations are delegated to the system threads in which they are performed. For example, a file read operation is blocking. So it is thrown into the system thread where the reading takes place and then the call-back is executed? Does Go create system threads? Or how does it happen?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2017-02-04
@pav5000

Go normally creates threads based on the number of processor cores (can be changed with the GOMAXPROC variable). Goroutines are spread between them, so that even elementary code can run in parallel in different threads.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question