1
0
mirror of https://github.com/moshix/mvs.git synced 2026-03-04 02:05:08 +00:00

added concurrency.go concurrency testing toy

This commit is contained in:
Moshix
2017-06-24 21:50:33 -05:00
parent e069923cbf
commit 795ecb2b63
5 changed files with 74 additions and 2 deletions

BIN
.blocksize.go.swp Normal file

Binary file not shown.

BIN
blocksize

Binary file not shown.

View File

@@ -33,13 +33,13 @@ func main() {
if dasd == "" { // no dasd type was input
fmt.Println("\nBLK205R No DASD type entered. ")
fmt.Println("\nBLK206R pls enter DASD type or restart with -h for list of DASD types")
fmt.Println("BLK206R pls enter DASD type or restart with -h for list of DASD types")
fmt.Scan(&dasd)
}
if lrecl == 0 { // no lrecl was input
fmt.Printf("\nBLK201R lrecl command line argument is not included.\n")
fmt.Println("\nBLK202R Please enter lrecl length: ")
fmt.Println("BLK202R Please enter lrecl length: ")
fmt.Scan(&lrecl)
}
if *helpPtr { // user asked for help

BIN
concurrency Executable file

Binary file not shown.

72
concurrency.go Normal file
View File

@@ -0,0 +1,72 @@
package main
/* 2017 copyright by moshix
with Apache license */
import (
"flag"
"fmt"
"time"
)
func ta(tamsec int) {
for i := 0; i < 9999999; i++ {
fmt.Println("Thread A: counter: ", i)
time.Sleep(time.Duration(tamsec) * time.Millisecond)
}
}
func tb(tbmsec int) {
for i := 0; i < 9999999; i++ {
fmt.Println("Thread B counter: ", i)
time.Sleep(time.Duration(tbmsec) * time.Millisecond)
}
}
func timeoutfunc(t chan bool, toutsec int) {
time.Sleep(time.Duration(toutsec) * time.Second)
t <- true
}
func main() {
var tamsec int = 300
var tbmsec int = 100
var toutsec int = 15
threadaPtr := flag.Int("tamsec", 300, "thread A millisecond wait time")
threadbPtr := flag.Int("tbmsec", 100, "thread B millisecond wait time")
toutPtr := flag.Int("tout", 15, "timeout period")
helpPtr := flag.Bool("help", false, "help flag")
flag.Parse()
if *helpPtr { //user asked for help...
fmt.Println("\nconcurrency is a Golang concurrency testing tool by moshix")
fmt.Println("Two parameters are needed, and a flag is optional:")
fmt.Println("-tamsec=nnn hundreds of milliseconds for thread A to wait")
fmt.Println("-tbmsec=nnn hundreds of milliseconds for thread B to wait")
fmt.Println("-tout=nn tens of seconds for time-out of all threads.")
fmt.Println("-help for this help dialog")
fmt.Println("\nconcurrency will in any case time out after 15 seconds")
fmt.Println("you can determine the relative and absolute veleocity of each thread by assigning sensible values in tamsec and tbmsec. Have fun!")
return
}
tamsec = *threadaPtr //assign argument of thread A wait time in msec
tbmsec = *threadbPtr //assign argument of thread B wait time in msec
toutsec = *toutPtr // assign time out in seconds
t := make(chan bool)
go timeoutfunc(t, toutsec)
go ta(tamsec)
go tb(tbmsec)
for {
tend := <-t
if tend == true {
fmt.Println("time-out from control and timing thread!")
return
}
}
}