for i := 0; i < mr.nMap; i++ {
DPrintf("worker number is %d
", mr.workerNumber)
worker_str = <- mr.registerChannel
DPrintf("Worker_str is %s
",worker_str)
args := &DoJobArgs{mr.file,"Map",i,mr.nReduce}
var reply DoJobReply
var ret bool
ret = call(worker_str, "Worker.DoJob", args, &reply)
if ret {
fmt.Println("wk worker done.
")
fmt.Println(worker_str)
mr.registerChannel <- worker_str // <=======stuck here
} else
{
fmt.Println("wk worker fail.
")
}
DPrintf("map finished.")
}
btw, mr is instance of this:
type MapReduce struct {
nMap int // Number of Map jobs
nReduce int // Number of Reduce jobs
file string // Name of input file
MasterAddress string
registerChannel chan string
DoneChannel chan bool
alive bool
l net.Listener
stats *list.List
// Map of registered workers that you need to keep up to date
Workers map[string]*WorkerInfo
// add any additional state here
workerNumber int
}
My code hang when I do this "mr.registerChannel <- worker_str "
I really don't understand why. worker_str is available, and I want to put this resource back after using this worker. Put it back to channel, let next job use available workers.
Why it hang? thanks