Download presentation

1
**New Go Programming Language by Google**

2
**Concurrent Programming**

3
Working Principle It works by taking a stream of all the natural numbers and introducing a sequence of filters one for each prime to winnow the multiples of that prime At each step we have a sequence of filters of the primes so far, and the next number to pop out is the next prime which triggers the creation of the next filter in the chain

4
Generate Function // Send the sequence 2, 3, 4, ... to channel 'ch'. Func generate(ch chan int) { for i := 2; ; i++ { ch <- i // Send 'i' to channel 'ch'. }

5
Filter Function func filter(in, out chan int, prime int) { for { i := <-in; // Receive value of new variable 'i' from 'in'. if i % prime != 0 { out <- i // Send 'i' to channel 'out'. }

6
Sieve Program func main() { ch := make(chan int); // Create a new channel. go generate(ch); // Start generate() as a goroutine. for { prime := <-ch; fmt.Println(prime); ch1 := make(chan int); go filter(ch, ch1, prime); ch = ch1 } }

Similar presentations

OK

Automating Checking of Models Built Using a Graphically Based Formal Language Robert John Walters.

Automating Checking of Models Built Using a Graphically Based Formal Language Robert John Walters.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To ensure the functioning of the site, we use **cookies**. We share information about your activities on the site with our partners and Google partners: social networks and companies engaged in advertising and web analytics. For more information, see the Privacy Policy and Google Privacy & Terms.
Your consent to our cookies if you continue to use this website.

Ads by Google

Ppt on eddy current brakes ppt Ppt on area of a circle Ppt on the road not taken by frost Ppt on nature and history of democracy in nepal Ppt on microcontroller based digital thermometer Ppt on electrical appliances and their uses Ppt on event handling in javascript something happens Download ppt on dot net Ppt on formation of joint stock company Ppt on resume writing