On Tuesday, 29 November 2016 13:10:49 UTC-5, Ian Lance Taylor wrote: > > On Tue, Nov 29, 2016 at 9:51 AM, Roger Alsing <roger...@gmail.com > <javascript:>> wrote: > > Coming from C++/C# background where locks/mutexes are considered evil > due to > > blocking threads. > > Due to how the Go goroutine scheduler works, are the Go counterpart of > those > > primitives "different"? > > > > Should I see the Go variants of these primitives more like yield points > > where the execution of a goroutine yields to let other goroutines run. > > And thus not resulting in the same resource code/weight as the > primitives > > has in other languages? > > Yes. A Go sync.Mutex blocks a goroutine, not a thread. Goroutines > are lighter weight than threads--they are basically just a stack. >
To elaborate: the key difference as it relates to your question is not really the size of the goroutine data structure or stack, but that a goroutine yield operation is usually handled entirely in user mode by the Go scheduler, avoiding execution of the the kernel's thread scheduler and a heavyweight context switch. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.