FAQ
Since Go is all about concurrency, wouldn't it make sense to mark
thread-safe types in the standard library as such? Like with a little tag
or symbol.

// ThreadSafe is a thread safe type that does this and that...
// [thread-safe]
type ThreadSafe struct {
// ...
}

func (t *ThreadSafe) DoSomething() {
// ...
}

--

Search Discussions

  • John Beshir at Sep 19, 2012 at 1:41 pm

    On Tue, Sep 18, 2012 at 3:35 PM, tomwilde wrote:
    Since Go is all about concurrency, wouldn't it make sense to mark
    thread-safe types in the standard library as such? Like with a little tag or
    symbol.

    // ThreadSafe is a thread safe type that does this and that...
    // [thread-safe]
    type ThreadSafe struct {
    // ...
    }

    func (t *ThreadSafe) DoSomething() {
    // ...
    }
    At the moment, where types are guaranteed thread safe for anything but
    concurrent reads (which are always safe), it's documented in the text
    describing the type. I think the main issues with a tag are:

    1) Not many types are thread safe. Thread safety is expensive, and in
    Go it is idiomatic to communicate or transfer ownership via channels
    rather than having concurrent access. In most cases supporting thread
    safe use would incur significant performance costs on more common
    usage.

    2) Where types do provide thread safety guarantees, they're often not
    absolute, instead guaranteeing that a particular set of concurrent
    operations are permitted together. A tag wouldn't be able to represent
    this information, and it is likely to be a significant amount of the
    useful information to know about thread safe types.

    3) Since idiomatic usage avoids sharing data between goroutines, and
    favours requests and transfers of ownership over thread safe data
    structures, the information it did provide would only occasionally be
    of use.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 18, '12 at 2:35p
activeSep 19, '12 at 1:41p
posts2
users2
websitegolang.org

2 users in discussion

Tomwilde: 1 post John Beshir: 1 post

People

Translate

site design / logo © 2021 Grokbase