Last active
November 11, 2018 10:29
-
-
Save mamaz/67d04e6c654564934a75fd0fc906a3ae to your computer and use it in GitHub Desktop.
Run Parallel
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 parallel | |
import ( | |
"Exercise/ConcurrencyAndParallel/printTask" | |
"fmt" | |
"runtime" | |
"sync" | |
"time" | |
) | |
// RunParallel - run program in parallel manner, | |
// using more than 1 Physical processors | |
func RunParallel() { | |
runtime.GOMAXPROCS(4) | |
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