"Go to" one line before the declaration

53 views
Skip to first unread message

jessie....@rococoglobaltech.com

unread,
Jul 17, 2019, 5:24:32 AM7/17/19
to golang-nuts
Can somebody explain this code?
How is the cpu doing? better than for{} and select {} in CPU usage?

package main

func main() {
start:
    goto start
}


Jan Mercl

unread,
Jul 17, 2019, 5:29:36 AM7/17/19
to jessie....@rococoglobaltech.com, golang-nuts
On Wed, Jul 17, 2019 at 11:24 AM <jessie....@rococoglobaltech.com> wrote:
>
> Can somebody explain this code?
> How is the cpu doing? better than for{} ...

Who claims it's doing better than `for {}`? IDK, I haven't tested, but
I guess it should perform the same bad way.

> ... and select {} in CPU usage?

Now that's a different story. Using `select {}` should burn 0% CPU in
the goroutine that executed the statement.

PS: Please post source code as black text on white, and, if possible,
as plain text only.

fge...@gmail.com

unread,
Jul 17, 2019, 5:44:55 AM7/17/19
to jessie....@rococoglobaltech.com, golang-nuts
The question is rather vague, though after making a few assumption
here are some hopefully useful pointers:

You can compare the different generated code snippets if you use -S
during compilation:
go tool compile -S mytestfile.go

A Quick Guide to Go's Assembler: https://golang.org/doc/asm
The go compilers implement this specification: https://golang.org/ref/spec

(Similary to Jan, for code please use only links to play.golang.org,
that's enough.)

hth


On 7/17/19, jessie....@rococoglobaltech.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 on the web visit
> https://groups.google.com/d/msgid/golang-nuts/17e87e55-5429-459d-8d68-66261c7d67dc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
Reply all
Reply to author
Forward
0 new messages