go language go routines channels
Download
Skip this Video
Download Presentation
Go Language * Go-Routines *Channels

Loading in 2 Seconds...

play fullscreen
1 / 9

Go Language * Go-Routines *Channels - PowerPoint PPT Presentation


  • 123 Views
  • Uploaded on

Go Language * Go-Routines *Channels. New Concepts. Do not communicate by sharing memory; instead, share memory by communicating. creating shared memory VS sharing by communication channels . Lightweight Threads ( Goroutines ). Goroutines.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Go Language * Go-Routines *Channels' - yardan


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
new concepts
New Concepts
  • Do not communicate by sharing memory; instead, share memory by communicating.
  • creating shared memory VSsharing by communication channels.
  • Lightweight Threads (Goroutines)
goroutines
Goroutines
  • a Go function or method executing concurrently in the same address space as other goroutines
  • OR it is a function executing in parallel with other goroutines in the same address space
  • It\'s not the same as a thread, coroutine, process, etc. It\'s a goroutine. [New term]
goroutines1
Goroutines
  • Goroutines are cheap.
  • at least for now, goroutines are pthreads
  • BUT In 6g , they\'re multiplexed onto threads.
  • So, one OS Thread could handle more than one goroutines [Lightweight thread]
  • Their stacks are small (a few kB) and grow as needed.
goroutines2
Goroutines
  • Example in C (Threads)
  • In Go, Goroutines are cooperatively scheduled by the Go scheduler
goroutines3
Goroutines
  • A running program consists of one or more goroutines.
  • Their design hides many of the complexities of thread creation and management. (mutex, queues etc.)
  • When a goroutine executes a blocking system call, no other goroutineis blocked.
c ommunication channels
Communication (Channels)
  • Go has a type called a channel that provides communication and synchronization capabilities.
  • A channel provides a mechanism for two concurrently executing functions (goroutines) to synchronize execution and communicate by passing a value of a specified element type
c ommunication channels1
Communication (Channels)
  • In its simplest form the type looks like this:

chanelementType

So to create a channel that can pass an integer :

varchannel_object_name= make(chanint)

  • communication operator : <-

channel <- value \\ send value

var get = <-channel \\ receive value

c ommunication channels2
Communication (Channels)
  • Unbuffered channel

ch:= make(chanint) \\ one element only

  • Buffered channel:

ch := make(chan type, value)

  • value : determine how many elements can be held
ad