Closed yuansudong closed 4 years ago
runtime.GOMAXPROCS(16) i := 1 go func() { for { log.Println("1 ==> ", i) runtime.Gosched() } }() go func() { for { log.Println("2 ==> ", i) runtime.Gosched() } }() go func() { for { log.Println("3 ==> ", i) runtime.Gosched() } }() go func() { for { log.Println("4 ==> ", i) runtime.Gosched() } }() go func() { for { log.Println("5 ==> ", i) runtime.Gosched() } }()
for {
i += 2
runtime.Gosched()
}
this is a simple test code
I have met before, many coroutines, if in the for cycle, did not call runtime.GoSched, then after a period of time, all the coroutines will not be executed
This happens for busy loops which contain computations but no (non-inlined) function calls. I don't think that go-nsq has any busy-loops, all of them call some non-trivial function which often blocks waiting to read, and either way is an automatic rescheduling point even if it did not block. See https://github.com/golang/go/issues/24543 for details.
The NSQ TCP protocol spec is described here: https://nsq.io/clients/tcp_protocol_spec.html
thanks
Hello, I read a part of your source code, I do not quite understand why you want to start reading and writing coroutines., and your for loop does not call runtime.GoSched.. I have met before, many coroutines, if in the for cycle, did not call runtime.GoSched, then after a period of time, all the coroutines will not be executed. Therefore, I want a NSQ TCP protocol document, I do not know you. Can you help me? If you are a Chinese, please reply me in Chinese.Thanks