Created
September 1, 2015 00:40
-
-
Save JamsMendez/10a3cfb797c81e278067 to your computer and use it in GitHub Desktop.
Procesos Paralelos en Go lang
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 main | |
import ( | |
"fmt" | |
"runtime" | |
"sync" | |
"time" | |
) | |
func main() { | |
runtime.GOMAXPROCS(2) | |
var waitGroup sync.WaitGroup | |
waitGroup.Add(4) | |
fmt.Println("Start Go Routines") | |
go func() { | |
defer waitGroup.Done() | |
time.Sleep(10 * time.Second) | |
fmt.Println("Finish Rutina 1") | |
}() | |
go func() { | |
defer waitGroup.Done() | |
time.Sleep(5 * time.Second) | |
fmt.Println("Finish Rutina 2") | |
}() | |
go func() { | |
defer waitGroup.Done() | |
time.Sleep(3 * time.Second) | |
fmt.Println("Finish Rutina 3") | |
}() | |
go func() { | |
defer waitGroup.Done() | |
time.Sleep(9 * time.Second) | |
fmt.Println("Finish Rutina 4") | |
}() | |
fmt.Println("Waiting ...") | |
waitGroup.Wait() | |
fmt.Println("Finish") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment