Hello.
I'm seeing a goroutine scheduling oddity that I don't understand. Can anyone explain why this is?
I have a function which occasionally writes to a file. I noticed that this was taking longer than I expected. It was because I was also Sync'ing the file. So I set up a goroutine just to do the sync, allowing the main function to continue. I used a buffered channel to pass the file info to it.
func initSyncFile() {
go func() {
for {
file := <-syncFileQue
err := (file.fileH).Sync()
...
}
}()
}
It executed ok, but I still saw a delay in the main function. I'm guessing that the new goroutine was set up on the same fiber, and that the channel transfer resulted in it running, thus pausing my main function. To avoid this, I added a "runtime.Gosched()" at the top of the sync function. I was expecting this to pause the sync function, allowing the main function to run. But there was no change. Why?
Some additional info: I Then replaces the Gosched() with a Sleep(1 time.Second). This worked! The main function continued right away. I found that this worked as long as the Sleep() was 5ms or longer.
I should note that this was on a Windows system. I believe that 5ms is the clock rate. I'm guessing that when the Sleep() is long enough, the reschedule takes place right away.
This solves my immediate problem. But it leaves me wondering why Gosched() didn't cause the same result.
Thanks,
John
John Souvestre New Orleans LA, USA 504-454-0899
Hi Jason.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/e2be1a43-71a2-4364-8f01-7b24210d2124n%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/01c401dd4700%248904fb00%249b0ef100%24%40Souvestre.com.
No. My question is about how the goroutine scheduling worked.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CADgY6e9VqiZZtt8fxA%2BEtCqQDfKCfgYmMe_O64GSM%2BSZg4B5HQ%40mail.gmail.com.
No. My question is about how the goroutine scheduling worked.