Skip to content

Commit

Permalink
Basic Go Routine.
Browse files Browse the repository at this point in the history
  • Loading branch information
baudekin committed Feb 25, 2024
1 parent ec18511 commit 5e56931
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions 01-basic-go-routine/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"fmt"
"runtime"
"sync"
)

func f2() {
defer wg.Done()
for i := 0; i < 100; i++ {
fmt.Printf("B")
}
fmt.Printf("\nFinished %s\n", "B")
}

var wg sync.WaitGroup

func main() {
//numOfCores := runtime.NumCPU()
//runtime.GOMAXPROCS(numOfCores)
runtime.GOMAXPROCS(1)
fmt.Println("Started")

var f3 = func() {
defer wg.Done()
for i := 0; i < 100; i++ {
fmt.Printf("C")
}
fmt.Printf("\nFinished %s\n", "C")
}

wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 100; i++ {
fmt.Printf("A")
}
fmt.Printf("\nFinished %s\n", "A")
}()
wg.Add(1)
go f2()
wg.Add(1)
go f3()

wg.Wait()
fmt.Println("Finished")
}

0 comments on commit 5e56931

Please sign in to comment.