Last active
November 11, 2018 10:30
-
-
Save mamaz/5f2f80950c19adae6a18bb9a499439bb to your computer and use it in GitHub Desktop.
Run in Concurrent Manner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package concurrency | |
import ( | |
"Exercise/ConcurrencyAndParallel/printTask" | |
"fmt" | |
"runtime" | |
"sync" | |
"time" | |
) | |
// RunConcurrently run program concurrently on one physical processor | |
func RunConcurrently() { | |
runtime.GOMAXPROCS(1) | |
var waitgroup sync.WaitGroup | |
waitgroup.Add(2) | |
fmt.Println("Starting goroutines") | |
start := time.Now() | |
go printTask.PrintNumbers(&waitgroup) | |
go printTask.PrintM(&waitgroup) | |
fmt.Println("Waiting to finish..") | |
waitgroup.Wait() | |
fmt.Println("Termination Program") | |
fmt.Println(time.Since(start)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment