This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Head First Go: the most famous adage of golang

 
Greenhorn
Posts: 27
IntelliJ IDE Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jay,
i want to ask  you about the famous go idiom - "do not communicate by sharing memory, share memory by communicating". Could you explain it, please?
 
Author
Posts: 22
5
Mac Ruby Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This refers to Go channels, which are used to communicate between goroutines.

Traditional languages use threads for concurrency, and have no concept analogous to channels. So if two threads need to share information, there's usually no choice but for both of them update some shared piece of memory, whether that's a global variable, database record, etc. But this can lead to race conditions, where one thread updates that shared memory while a different thread is actively working with it, leading to errors and bugs. You can mitigate the problem by having the threads signal that they're updating the value, using mutexes and the like, but that's 1. a pain to code and 2. cuts into the speed benefits of multithreading.

Channels are specifically designed for communication between goroutines. You can be certain that only one goroutine is writing a value, and only one goroutine is reading a particular value. Go offers both buffered and unbuffered channels. An unbuffered channel automatically synchronizes goroutines: a goroutine that writes to a channel will block until another goroutine reads from it, and vice-versa.

This all probably sounds confusing to those who haven't done concurrent programming before. So here's the TLDR: Go makes concurrent programming easier and less error-prone than other languages.
 
Timur Radzhabov
Greenhorn
Posts: 27
IntelliJ IDE Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Things got a little bit clearer for me. Thanks!
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!