Example #1
0
func NewWalker() *Walker {
	var w = new(Walker)
	w.gq = dispatch.New(20)
	w.lock = new(sync.Mutex)
	w.wg = new(sync.WaitGroup)
	w.done = make(chan bool)
	w.paths = make([]string, 0, 1)
	w.sizes = make([]int64, 0, 1)
	return w
}
Example #2
0
// Run n daisy-chained k-task workflows simultaneously
func Example(n, k int) [][]int {
	numChan := n*opt.maxgo + 1 // > (# chains)*(# threads) [indep. of chain length]
	d := dispatch.New(opt.maxgo)
	cb := NewChannelBucket(numChan)
	wg := new(sync.WaitGroup)
	out := make([][]int, n)

	t1 := time.Nanoseconds()
	go d.Start()
	wg.Add(n)
	for id := 0; id < n; id++ {
		go ExampleDaisyChain(k, id, out, d, cb, wg)
	}
	wg.Wait()
	d.Stop()
	t2 := time.Nanoseconds()

	deltat := t2 - t1
	sec := deltat / 1e9
	frac := (deltat % 1e9) / 1e6

	fmt.Printf("Number of jobs %d; Maximum queue length %d; %d.%-3ds", n*k, d.MaxLen(), sec, frac)
	return out
}
Example #3
0
 */
import (
	"flag"
	"fmt"
	"github.com/bmatsuo/dispatch"
	"github.com/bmatsuo/dispatch/queues"
	"log"
	"os"
	"rand"
	"sync"
	"time"
)

var (
	maxswimmers   = 10
	fifoDispatch  = dispatch.New(maxswimmers)
	swimDispatch  = dispatch.NewCustom(maxswimmers, queues.NewPriorityQueue())
	vecDispatch   = dispatch.NewCustom(maxswimmers, queues.NewVectorPriorityQueue())
	arrayDispatch = dispatch.NewCustom(maxswimmers, queues.NewArrayPriorityQueue())
	finishLine    = new(sync.WaitGroup)
)

type Athlete struct {
	Btime, Stime, Rtime int64
}

func RandomAthlete() Athlete {
	var (
		Btime = rand.Int63n(int64(opt.maxbtime) * 1e9)
		Stime = rand.Int63n(int64(opt.maxstime) * 1e9)
		Rtime = rand.Int63n(int64(opt.maxrtime) * 1e9)