1 / 9

Go Language * Go-Routines *Channels

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.

yardan
Télécharger la présentation

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Go Language *Go-Routines*Channels

  2. New Concepts • Do not communicate by sharing memory; instead, share memory by communicating. • creating shared memory VSsharing by communication channels. • Lightweight Threads (Goroutines)

  3. 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]

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

  5. Goroutines • Example in C (Threads) • In Go, Goroutines are cooperatively scheduled by the Go scheduler

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

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

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

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

More Related