1 Matching Annotations
  1. Jan 2023
    1. v.mux.Lock() if !v.visited[url] { body, urls, err := fetcher.Fetch(url) if err != nil { fmt.Println(err) v.visited[url] = true v.mux.Unlock() quit <- true return } v.visited[url] = true fmt.Printf("found: %s %q\n", url, body) v.mux.Unlock() for _, u := range urls { childquit := make(chan bool) go MyCrawl(u, depth-1, fetcher, childquit, v) <-childquit } } else { v.mux.Unlock() }

      sync.Mutex 操作的是 visited,那是否没必要将其他的代码也包含在 Lock 与 Unlock 之间