Goroutine-safe vs Thread-safe

1,528 views
Skip to first unread message

deck...@gmail.com

unread,
Nov 8, 2013, 4:43:08 PM11/8/13
to golan...@googlegroups.com
Hi GoNuts,

I asked a question a few days ago about the intricacies of concurrency in Go when GOMAXPROCS was set to 1.


To quote Lars:

No. The Go Memory Model is defined in terms of goroutines, not threads. 
Unsynchronized concurrent access to shared data from multiple goroutines 
is not safe as soon as one of them is a writer. The implementation is 
free to make use of that. 

If Go defines everything in terms of goroutine safety and not threads why does the documentation for a Map (as an example) refer to a map as not being "thread-safe"?   Is this just inconsistency within the docs?  Or is it proper to say that a Map is not thread-safe?  Here is the docs i'm referring to: http://golang.org/doc/faq#atomic_maps and also here:

I guess I'm getting confused if these terms are interchangeable or not.  If they are not interchangeable perhaps the docs should be updated to reflect this?  I personally feel that having a distinction is important because although it's possible to think of Goroutines as light-weight threads, to call them threads is still wrong.  

Anyone care to shed some light?

Thanks in advance,

-Ralph

P.S. Not trying to nitpick, just really trying to have an intuitive understanding on Go.


Dominik Honnef

unread,
Nov 8, 2013, 4:54:06 PM11/8/13
to golan...@googlegroups.com
You can freely substitute "thread-safe" with "goroutine-safe" in Go
documentation, where it occurs.

Unless documentation very explicitly refers to actual threads (such as
the fact that using OpenGL with cgo requires pinning a goroutine to a
specific thread), it means goroutines when it says "thread-safe".

It might be noted that most of the documentation will avoid the term, in
favour of "(not) safe for concurrent access". Maybe the FAQ entry should
be updated. Especially because it refers to "access from multiple
threads", which is quite inaccurate.

Dmitry Vyukov

unread,
Nov 9, 2013, 3:05:08 AM11/9/13
to deck...@gmail.com, golang-nuts

Goroutine-safe is not well-established term. While thread-safe is, and it means safe for concurrent access.

sent from phone

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

Dmitry Vyukov

unread,
Nov 9, 2013, 3:06:07 AM11/9/13
to golang-nuts

+1

Reply all
Reply to author
Forward
0 new messages