Last active
August 29, 2015 14:02
-
-
Save bolilla/f30de19882f261929a69 to your computer and use it in GitHub Desktop.
GoPadawan Concurrencia Contador Atomico
This file contains 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" | |
"sync/atomic" | |
) | |
type contador int32 | |
func (c *contador) incrementar() int32 { | |
return atomic.AddInt32((*int32)(c), 1) | |
} | |
func (c *contador) decrementar() int32 { | |
return atomic.AddInt32((*int32)(c), -1) | |
} | |
func (c *contador) get() int32 { | |
return atomic.LoadInt32((*int32)(c)) | |
} | |
func main() { | |
var cont contador | |
fmt.Println("Pequeño Padawan, el contador es", cont) | |
cont.incrementar() | |
fmt.Println("Pequeño Padawan, el contador es", cont) | |
cont.decrementar() | |
fmt.Println("Pequeño Padawan, el contador es", cont) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment