Go language go routines channels
This presentation is the property of its rightful owner.
Sponsored Links
1 / 9

Go Language * Go-Routines *Channels PowerPoint PPT Presentation

  • Uploaded on
  • Presentation posted in: General

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.

Download Presentation

Go Language * Go-Routines *Channels

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

Go language go routines channels

Go Language *Go-Routines*Channels

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)



  • 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]



  • 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.



  • Example in C (Threads)

  • In Go, Goroutines are cooperatively scheduled by the Go scheduler



  • 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:


    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

  • Login