Atomic in WWW
This commit is contained in:
parent
2344b12466
commit
0775f15607
3 changed files with 25 additions and 2 deletions
|
|
@ -10,13 +10,18 @@ import (
|
|||
var count int32
|
||||
|
||||
func handleAll(w http.ResponseWriter, r *http.Request) {
|
||||
temp := atomic.LoadInt32(&count)
|
||||
atomic.AddInt32(&count, 1)
|
||||
fmt.Println("count:", temp)
|
||||
}
|
||||
|
||||
func getCounter(w http.ResponseWriter, r *http.Request) {
|
||||
temp := atomic.LoadInt32(&count)
|
||||
fmt.Println("Count:", temp)
|
||||
fmt.Fprintf(w, "<h1 align=\"center\">%d</h1>", count)
|
||||
}
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU() - 1)
|
||||
http.HandleFunc("/getCounter", getCounter)
|
||||
http.HandleFunc("/", handleAll)
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue