Beispiel #1
0
func cmdtorture(ns *g9pc.Ns, s []string) {
	path := "."
	if len(s) > 0 {
		path = s[0]
	}
	t := &traverser{
		out:  make(chan string),
		refc: make(chan int),
		//		tokc: make(chan bool, 2),
	}
	if len(s) > 1 {
		max, err := strconv.Atoi(s[1])
		if err != nil {
			fmt.Fprintf(os.Stderr, "max?: %v\n", err)
			return
		}
		t.tokc = make(chan bool, max)
		for i := 0; i < max; i++ {
			t.tokc <- true
		}
	}
	fid, err := ns.Walk(path)
	if fid == nil {
		fmt.Fprintf(os.Stderr, "cannot walk to %s: %v\n", s[0], err)
		return
	}
	ref := 1
	maxref := 1
	go func() {
		t.traverse(fid, path, "", make(chan bool, 1))
		t.refc <- -1
	}()
	for ref > 0 {
		select {
		case s := <-t.out:
			fmt.Print("************ ", s)
		case r := <-t.refc:
			ref += r
			if ref > maxref {
				maxref = ref
			}
		}
	}
	fmt.Printf("\n")
	fmt.Printf("max procs %d\n", maxref)
}