FAQ
Hi all
I just write a stackChannel model for fun. But the test sometimes
failed at read data from channel. code is here:
https://github.com/tw4452852/stackChannel. Thx.

--

Search Discussions

  • Steve wang at Nov 22, 2012 at 1:22 pm
    As far as I know, bytes.Buffer.Read() and bytes.Buffer.Write() are not
    goroutine safe.
    On Thursday, November 22, 2012 8:19:17 PM UTC+8, Totoro Ghibli wrote:

    Hi all
    I just write a stackChannel model for fun. But the test sometimes
    failed at read data from channel. code is here:
    https://github.com/tw4452852/stackChannel. Thx.
    --
  • Steve wang at Nov 22, 2012 at 1:33 pm
    Things of this kind often result from wrong synchronization.
    With a mutex's protection, it works fine.
    On Thursday, November 22, 2012 9:22:10 PM UTC+8, steve wang wrote:

    As far as I know, bytes.Buffer.Read() and bytes.Buffer.Write() are not
    goroutine safe.
    On Thursday, November 22, 2012 8:19:17 PM UTC+8, Totoro Ghibli wrote:

    Hi all
    I just write a stackChannel model for fun. But the test sometimes
    failed at read data from channel. code is here:
    https://github.com/tw4452852/stackChannel. Thx.
    --
  • Tw at Nov 22, 2012 at 1:34 pm

    ? 2012/11/22 21:22, steve wang ??:
    As far as I know, bytes.Buffer.Read() and bytes.Buffer.Write() are not
    goroutine safe.

    On Thursday, November 22, 2012 8:19:17 PM UTC+8, Totoro Ghibli wrote:

    Hi all
    I just write a stackChannel model for fun. But the test
    sometimes
    failed at read data from channel. code is here:
    https://github.com/tw4452852/stackChannel
    <https://github.com/tw4452852/stackChannel>. Thx.

    --
    But I haven't found something about this in bytes pkg doc...

    --
  • Steve wang at Nov 22, 2012 at 1:46 pm

    On Thursday, November 22, 2012 9:34:14 PM UTC+8, Totoro Ghibli wrote:
    于 2012/11/22 21:22, steve wang 写道:

    As far as I know, bytes.Buffer.Read() and bytes.Buffer.Write() are not
    goroutine safe.
    On Thursday, November 22, 2012 8:19:17 PM UTC+8, Totoro Ghibli wrote:

    Hi all
    I just write a stackChannel model for fun. But the test sometimes
    failed at read data from channel. code is here:
    https://github.com/tw4452852/stackChannel. Thx.
    --



    But I haven't found something about this in bytes pkg doc...
    I think it's an default rule: nothing is goroutine safe except those they
    tell you.

    --
  • Tw at Nov 22, 2012 at 2:16 pm
    于 2012/11/22 21:39, steve wang 写道:

    On Thursday, November 22, 2012 9:34:14 PM UTC+8, Totoro Ghibli wrote:

    于 2012/11/22 21:22, steve wang 写道:
    As far as I know, bytes.Buffer.Read() and bytes.Buffer.Write()
    are not goroutine safe.

    On Thursday, November 22, 2012 8:19:17 PM UTC+8, Totoro Ghibli
    wrote:

    Hi all
    I just write a stackChannel model for fun. But the test
    sometimes
    failed at read data from channel. code is here:
    https://github.com/tw4452852/stackChannel
    <https://github.com/tw4452852/stackChannel>. Thx.

    --
    But I haven't found something about this in bytes pkg doc...

    I think it's an default rule: nothing is goroutine safe except those
    they tell you.

    --
    But I don't understand following two things:
    1. Why the things from read are all "0" sometimes as if
    bytes.Buffer.Read will overwrite the previous.
    2. Even if the bytes.Buffer isn't goroutine safe, I will read from it
    until enough.

    --
  • Steve wang at Nov 22, 2012 at 2:30 pm

    On Thursday, November 22, 2012 10:17:05 PM UTC+8, Totoro Ghibli wrote:
    于 2012/11/22 21:39, steve wang 写道:


    On Thursday, November 22, 2012 9:34:14 PM UTC+8, Totoro Ghibli wrote:

    于 2012/11/22 21:22, steve wang 写道:

    As far as I know, bytes.Buffer.Read() and bytes.Buffer.Write() are not
    goroutine safe.
    On Thursday, November 22, 2012 8:19:17 PM UTC+8, Totoro Ghibli wrote:

    Hi all
    I just write a stackChannel model for fun. But the test sometimes
    failed at read data from channel. code is here:
    https://github.com/tw4452852/stackChannel. Thx.
    --



    But I haven't found something about this in bytes pkg doc...
    I think it's an default rule: nothing is goroutine safe except those they
    tell you.

    --



    But I don't understand following two things:
    1. Why the things from read are all "0" sometimes as if bytes.Buffer.Read
    will overwrite the previous.
    2. Even if the bytes.Buffer isn't goroutine safe, I will read from it
    until enough.
    According to my experience, anything strange could happen when more than
    one threads/goroutines contend for the same data.
    But I couldn't tell more because I haven't looked into the corresponding
    source code yet.
    Maybe someone here will explain it clearly.

    --
  • Steve wang at Nov 22, 2012 at 2:37 pm

    On Thursday, November 22, 2012 10:17:05 PM UTC+8, Totoro Ghibli wrote:
    于 2012/11/22 21:39, steve wang 写道:


    On Thursday, November 22, 2012 9:34:14 PM UTC+8, Totoro Ghibli wrote:

    于 2012/11/22 21:22, steve wang 写道:

    As far as I know, bytes.Buffer.Read() and bytes.Buffer.Write() are not
    goroutine safe.
    On Thursday, November 22, 2012 8:19:17 PM UTC+8, Totoro Ghibli wrote:

    Hi all
    I just write a stackChannel model for fun. But the test sometimes
    failed at read data from channel. code is here:
    https://github.com/tw4452852/stackChannel. Thx.
    --



    But I haven't found something about this in bytes pkg doc...
    I think it's an default rule: nothing is goroutine safe except those they
    tell you.

    --



    But I don't understand following two things:
    1. Why the things from read are all "0" sometimes as if bytes.Buffer.Read
    will overwrite the previous.
    2. Even if the bytes.Buffer isn't goroutine safe, I will read from it
    until enough.
    According to my experience, anything strange could happen when more than
    one threads/goroutines contend for the same data.
    But I couldn't tell more because I haven't looked into the corresponding
    source code yet.
    Maybe someone here will explain it clearly.

    --
  • Roger peppe at Nov 22, 2012 at 4:18 pm
    steve wang is correct. no type should be assumed to be thread safe
    unless documented otherwise.

    On 22 November 2012 12:20, Tw wrote:
    Hi all
    I just write a stackChannel model for fun. But the test sometimes failed
    at read data from channel. code is here:
    https://github.com/tw4452852/stackChannel. Thx.

    --
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 22, '12 at 12:19p
activeNov 22, '12 at 4:18p
posts9
users3
websitegolang.org

3 users in discussion

Steve wang: 5 posts Tw: 3 posts Roger peppe: 1 post

People

Translate

site design / logo © 2021 Grokbase