• 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

Concurrency in Go

 
Ranch Hand
Posts: 458
Scala jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What concurrency model does Go use? Is it easier to use than Java's?
 
Author
Posts: 14
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note, Chapter 3 from Go in Practice talks about concurrency. It's a free download (warning: pdf).

The Go model for concurrency is heavily inspired by CSP. In Go, the runtime manages a number of threads. Typically this is ~1 per core but it is configurable if you want to change it. Concurrency is via goroutines, which are concurrent functions that are scheduled and run on those threads. They are sometimes called lightweight threads. They are lightweight as far as footprint but are not technically threads.

To start of a goroutine you simple use the go keyword. For example:


The Go runtime schedules goroutines. It's not unusual for thousands or more goroutines to be going at the same time or to have had millions of them over the life of a running application.

The functions can also be closures and be run as goroutines.

Communication happens through channels that pass instances and other variables between goroutines.

Some of this is also covered in chapter 1 which is a free download. There are even pictures.

Conceptually, it reminds me of JavaScript but there is the ability to communicate between concurrent functions and the runtime is multithreaded.

I'll let you decide if it's easy.
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
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!