Re: [go-nuts] Cross compiling from Windows to Linux produces non-working go routines
On Wednesday, March 8, 2017 at 9:50:09 AM UTC-5, Chris Hines wrote: > > The infinite loops in each function will busy loop and consume a core > without allowing the runtime scheduler a chance to run other goroutines on > that core. If your virtual machine doesn't have enough cores then some > goroutines may starve. > > Change the loops to select {} to block infinitely without busy looping and > see if that behaves as expected. > I like to use "<-make(chan interface{}) " as a one line "block forever" statement. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Cross compiling from Windows to Linux produces non-working go routines
Fantastic! In my main program I had the main in an infinite for. That was burning the only core of my vm. I've changed that to select and now it's working fine. Thank you Konstantin, for your answer, too. El miércoles, 8 de marzo de 2017, 11:50:09 (UTC-3), Chris Hines escribió: > > The infinite loops in each function will busy loop and consume a core > without allowing the runtime scheduler a chance to run other goroutines on > that core. If your virtual machine doesn't have enough cores then some > goroutines may starve. > > Change the loops to select {} to block infinitely without busy looping and > see if that behaves as expected. > > On Wednesday, March 8, 2017 at 9:20:39 AM UTC-5, Rodrigo Pardo wrote: >> >> I've made this test program >> >> >> package main >> >> import "fmt" >> >> func func1() { >> fmt.Println("running func1") >> for { >> >> } >> } >> >> func func2() { >> fmt.Println("running func1") >> for { >> >> } >> } >> >> func func3() { >> fmt.Println("running func1") >> for { >> >> } >> } >> >> func main() { >> >> go func1() >> fmt.Println("run func1") >> go func2() >> fmt.Println("run func2") >> go func3() >> fmt.Println("run func3") >> for { >> >> } >> >> } >> >> On windows I get >> go run test.go >> >> run func1 >> running func1 >> run func2 >> running func1 >> run func3 >> running func1 >> >> On Linux, cross compiled (go build -v) I get >> ./test >> >> run func1 >> run func2 >> run func3 >> >> Now I've installed go to my linux and I'm compiling directly from there >> (gopath set to shared folder) >> go run test.go >> >> run func1 >> run func2 >> run func3 >> >> >> El miércoles, 8 de marzo de 2017, 10:48:26 (UTC-3), Ayan George escribió: >>> >>> >>> >>> On 03/08/2017 08:30 AM, asc...@gmail.com wrote: >>> >>> > In the main function I call various go routines, I've set println >>> after >>> > each call, so I know they are being executed. But I don't get the >>> > printlns I've set inside of some of those routines, for the same >>> purpose. >>> > >>> >>> So you are seeing some Println()s but not others or are you not seeing >>> any Println()s at all? >>> >>> -ayan >>> >> -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Cross compiling from Windows to Linux produces non-working go routines
On Wed, 8 Mar 2017 06:20:25 -0800 (PST) asci...@gmail.com wrote: > I've made this test program > > > package main > > import "fmt" > > func func1() { > fmt.Println("running func1") > for { > > } [...] > func main() { > > go func1() > fmt.Println("run func1") > go func2() > fmt.Println("run func2") > go func3() > fmt.Println("run func3") > for { > > } > > } [...] Each for { } produces a "busy loop" which burns a single CPU core/socket and effectively binds a goroutine it executes in to its underlying OS thread. This means that if your Linux VM has different idea of CPU cores/sockets available than your Windows host (supposedly, fewer), you will get different printouts because certain goroutines simply won't have a chance to run. Please read up any Go book / HOWTO on goroutine synchronization techniques and use any of them to properly synchronize your main() with your goroutines (sync.WaitGroup might be the simplest one for this case). Don't ever use busy loops. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Cross compiling from Windows to Linux produces non-working go routines
The infinite loops in each function will busy loop and consume a core without allowing the runtime scheduler a chance to run other goroutines on that core. If your virtual machine doesn't have enough cores then some goroutines may starve. Change the loops to select {} to block infinitely without busy looping and see if that behaves as expected. On Wednesday, March 8, 2017 at 9:20:39 AM UTC-5, Rodrigo Pardo wrote: > > I've made this test program > > > package main > > import "fmt" > > func func1() { > fmt.Println("running func1") > for { > > } > } > > func func2() { > fmt.Println("running func1") > for { > > } > } > > func func3() { > fmt.Println("running func1") > for { > > } > } > > func main() { > > go func1() > fmt.Println("run func1") > go func2() > fmt.Println("run func2") > go func3() > fmt.Println("run func3") > for { > > } > > } > > On windows I get > go run test.go > > run func1 > running func1 > run func2 > running func1 > run func3 > running func1 > > On Linux, cross compiled (go build -v) I get > ./test > > run func1 > run func2 > run func3 > > Now I've installed go to my linux and I'm compiling directly from there > (gopath set to shared folder) > go run test.go > > run func1 > run func2 > run func3 > > > El miércoles, 8 de marzo de 2017, 10:48:26 (UTC-3), Ayan George escribió: >> >> >> >> On 03/08/2017 08:30 AM, asc...@gmail.com wrote: >> >> > In the main function I call various go routines, I've set println after >> > each call, so I know they are being executed. But I don't get the >> > printlns I've set inside of some of those routines, for the same >> purpose. >> > >> >> So you are seeing some Println()s but not others or are you not seeing >> any Println()s at all? >> >> -ayan >> > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Cross compiling from Windows to Linux produces non-working go routines
I've made this test program package main import "fmt" func func1() { fmt.Println("running func1") for { } } func func2() { fmt.Println("running func1") for { } } func func3() { fmt.Println("running func1") for { } } func main() { go func1() fmt.Println("run func1") go func2() fmt.Println("run func2") go func3() fmt.Println("run func3") for { } } On windows I get go run test.go run func1 running func1 run func2 running func1 run func3 running func1 On Linux, cross compiled (go build -v) I get ./test run func1 run func2 run func3 Now I've installed go to my linux and I'm compiling directly from there (gopath set to shared folder) go run test.go run func1 run func2 run func3 El miércoles, 8 de marzo de 2017, 10:48:26 (UTC-3), Ayan George escribió: > > > > On 03/08/2017 08:30 AM, asc...@gmail.com wrote: > > > In the main function I call various go routines, I've set println after > > each call, so I know they are being executed. But I don't get the > > printlns I've set inside of some of those routines, for the same > purpose. > > > > So you are seeing some Println()s but not others or are you not seeing > any Println()s at all? > > -ayan > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Cross compiling from Windows to Linux produces non-working go routines
On 03/08/2017 08:30 AM, asci...@gmail.com wrote: > In the main function I call various go routines, I've set println after > each call, so I know they are being executed. But I don't get the > printlns I've set inside of some of those routines, for the same purpose. > So you are seeing some Println()s but not others or are you not seeing any Println()s at all? -ayan -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Cross compiling from Windows to Linux produces non-working go routines
Hello, I'm running go1.8 windows/amd64 I have a working program, which I want to compile to Linux. So I set GOOS=linux and then go build I have a virtual machine with Debian 7. And I run the program. However it functions incorrectly. In the main function I call various go routines, I've set println after each call, so I know they are being executed. But I don't get the printlns I've set inside of some of those routines, for the same purpose. Can this have something to do with the program being cross compiled? What should I test to see if I can get it working? Thanks in advance Rodrigo -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.