Atomic in WWW

This commit is contained in:
Mihalis Tsoukalos 2019-05-01 17:07:06 +03:00
commit 0775f15607
3 changed files with 25 additions and 2 deletions

View file

@ -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)
}

View file

@ -0,0 +1,9 @@
package main
import (
"fmt"
)
func main() {
}

View file

@ -0,0 +1,9 @@
package main
import (
"fmt"
)
func main() {
}