Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tour: Concurrency: Exercise Web Crawler would profit from hint about mutex #13110

Closed
bernhardreiter opened this issue Oct 30, 2015 · 6 comments
Closed

Comments

@bernhardreiter
Copy link

Hi,
just took the tour, it was nice.

I have a suggestion for the last exercise-web-crawler.go.
I could solve the task to run the crawlers in parallel using the channels,
but the task to only crawl urls once could need more hints, it was too hard.

As I am only a beginner once, I'm reporting it.

As far as I say, solving the task of "crawling urls only onces" requires either

  • two way communication to ask via a channel (which was not explained
    before and probably would need a way to build individual channels to each goroutine or a way to have them all ask over one common channel) if an url has already been crawled or
  • a mutex like mechanism to access a common map

Both have not been explained in the tour before. The reference solution uses the mutex.
Now I could have read up on the "sync" packages to use a mutex, but because
page concurrency/1 said that this was rarely necessary, I expected a higher level way to exist.
Which I could not find in a reasonable timeframe so I gave up and looked at the solution in the source.

My suggestions are:

  • Add a hint that you should read up on the "sync" package and use a mutex for the second task.
  • Possibly hint at a pattern how two goroutines could ask each other something over a channel (if such a pattern exist) in the channel part.
  • Consider adding the anounymous function that is used in the tour/solutions/webcrawler.go
    file to start a go routine to a previous example, I found it non-obvious when looking at webcrawler.go

tour master commit 1c790b9f8bfefe44f33fbc9aacf5a6bc06027321 Date: Tue Oct 20 14:55:43 2015 -0700
Chromium with go1.5.1 in i386 in Debian GNU/Linux.

Best Regards,
Bernhard

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Oct 31, 2015
@ianlancetaylor
Copy link
Member

CC @adg @campoy

@campoy
Copy link
Contributor

campoy commented Dec 3, 2015

Hi @bernhardreiter, thanks for your feedback!

I'm going to try to add a couple of slides mentioning sync.Mutex before that exercise and a hint on the exercise description too.

Also, awesome job finishing the tour!! Your rock 👍

@campoy
Copy link
Contributor

campoy commented Dec 4, 2015

Proposed change: https://go-review.googlesource.com/17403

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/17403 mentions this issue.

@bernhardreiter
Copy link
Author

Hi Francesc,

thank for maintaining the gotour. :)

Took a quick look at your proposed change:

  • It is good to have sync.Mutex explained. Now the solution of the
    last exercise should be doable.
  • The mention on the last exercise might be a bit too indirect.
    Instead of "but maps are not safe for concurrent use!", maybe
    be "but maps alone are not safe for concurrent use!" to strongly
    suggest that sync.Mutex can secure maps, so they can be used
    if used properly.

Best,
Bernhard

@campoy
Copy link
Contributor

campoy commented Dec 4, 2015

CL updated

@golang golang locked and limited conversation to collaborators Dec 14, 2016
gopherbot pushed a commit to golang/website that referenced this issue May 26, 2021
sync.Mutex is needed to solve the last exercise of the tour

Fixes golang/go#13110

Change-Id: I0b10f8c0fc0e3c656377b93bdbf40e38c5cb762b
Reviewed-on: https://go-review.googlesource.com/17403
Reviewed-by: Rob Pike <r@golang.org>
X-Tour-Commit: ee3e019a7c9cb1e8e5889af4089bee4195a27ea9
passionSeven added a commit to passionSeven/website that referenced this issue Oct 18, 2022
sync.Mutex is needed to solve the last exercise of the tour

Fixes golang/go#13110

Change-Id: I0b10f8c0fc0e3c656377b93bdbf40e38c5cb762b
Reviewed-on: https://go-review.googlesource.com/17403
Reviewed-by: Rob Pike <r@golang.org>
X-Tour-Commit: ee3e019a7c9cb1e8e5889af4089bee4195a27ea9
KimuraDanaka119 added a commit to KimuraDanaka119/go-tour-jp that referenced this issue Jun 4, 2023
sync.Mutex is needed to solve the last exercise of the tour

Fixes golang/go#13110

Change-Id: I0b10f8c0fc0e3c656377b93bdbf40e38c5cb762b
Reviewed-on: https://go-review.googlesource.com/17403
Reviewed-by: Rob Pike <r@golang.org>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants