my net house

WAHEGURU….!

Art of Concurrency in Golang…..Part2…(Some Pure Basics of Go-Routines, to Blow your mind.)

Some Pure Basics of Go-Routines, to Blow your mind like Dope.
When you can run Multiple Anonymous G-Routines. Each Go-Routine Will
Exist after Wait.done() Till the n wg.wait() for the main Thread Will hold the Program
After all Go-Routines will be Done Completly.
But for any call of Anonymous Function() Calling your Go-Rotine’s Calling will never be Synchronous!

// Sample program to show how to create goroutines and
// how the scheduler behaves.
package main

import (
“fmt”
“runtime”
“sync”
)

func init() {

// Allocate one logical processor for the scheduler to use.
runtime.GOMAXPROCS(1)
}

func main() {

// wg is used to manage concurrency.
var wg sync.WaitGroup
wg.Add(2)

fmt.Println(“Start Goroutines”)

// Create a goroutine from the lowercase function.
go func() {
lowercase()
wg.Done()
}()

// Create a goroutine from the uppercase function.
go func() {
uppercase()
wg.Done()
}()

// Wait for the goroutines to finish.
fmt.Println(“Waiting To Finish”)
wg.Wait()

fmt.Println(“\nTerminating Program”)
}

// lowercase displays the set of lowercase letters three times.
func lowercase() {

// Display the alphabet three times
for count := 0; count < 3; count++ {
for r := ‘a’; r <= ‘z’; r++ {
fmt.Printf(“%c “, r)
}
}
}

// uppercasea displays the set of uppercase letters three times.
func uppercase() {

// Display the alphabet three times
for count := 0; count < 3; count++ {
for r := ‘A’; r <= ‘Z’; r++ {
fmt.Println(“–“)
fmt.Printf(“%c “, r)
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: