FAQ
I read this article again http://golang.org/ref/mem
It read dry. Style like math article. Difficult to read at the beginning.
But the last line is IMPORTANT and easy to read.

Just use sync and channel instead of any OLD C style tips to prevent race
condition.

I've written some test code to try it.

go test -race -v -run I1 # detected
go test -race -v -run I2 # detected
go test -race -v -run I3 -timeout 3s # hang
go test -race -v -run I4 -timeout 3s # hang

The strange thing is: go routine hangs and the testing package's -timeout
option can not work.

--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Dmitry Vyukov at May 15, 2013 at 12:48 pm

    On Wed, May 15, 2013 at 6:45 AM, dlin wrote:
    I read this article again http://golang.org/ref/mem
    It read dry. Style like math article. Difficult to read at the beginning.
    But the last line is IMPORTANT and easy to read.

    Just use sync and channel instead of any OLD C style tips to prevent race
    condition.

    I've written some test code to try it.

    go test -race -v -run I1 # detected
    go test -race -v -run I2 # detected
    go test -race -v -run I3 -timeout 3s # hang
    go test -race -v -run I4 -timeout 3s # hang

    The strange thing is: go routine hangs and the testing package's -timeout
    option can not work.
    The program "hangs" because Go currently has non-preemptive scheduler,
    so it just executes the following loop infinitely:

    for i4g == nil {
    }

    It does allows to run the timeout goroutine as well.
    You need to change it to:

    for i4g == nil {
         runtime.Gosched()
    }

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 15, '13 at 2:45a
activeMay 15, '13 at 12:48p
posts2
users2
websitegolang.org

2 users in discussion

Dmitry Vyukov: 1 post Dlin: 1 post

People

Translate

site design / logo © 2023 Grokbase