lp://staging/tomb

Created by Gustavo Niemeyer and last modified
Get this branch:
bzr branch lp://staging/tomb
Only Gustavo Niemeyer can upload to this branch. If you are Gustavo Niemeyer please log in for upload directions.

Branch merges

Related bugs

Related blueprints

Branch information

Owner:
Gustavo Niemeyer
Project:
Tomb
Status:
Development

Recent revisions

18. By Gustavo Niemeyer

Project moved to https://gopkg.in/tomb.v1

17. By Gustavo Niemeyer

Fix race found by race detector, and reported by Dave Cheney.

Here is more information than you'll want to know:

If goroutine 1 is doing:

    t.Kill(nil)
    t.Wait()

and goroutine 2 is doing:

    t.Wait()

and goroutine 3 is doing:

    t.Done()

There is a race, because goroutine 3 could finish first, and then
goroutine 1 might run, and the memory model won't guarantee that
goroutine 2 actually sees t.reason recorded by the Kill(nil) of
goroutine 1.

This specific case is more of a theoretical problem than a real one,
for the following reasons:

- The memory model guarantees that the close(t.done) performed
  by t.Done() will Happen Before the <-t.done done by either t.Wait,
  which means both goroutine 1 and 2 will always necessarily see a
  real error coming out of the goroutine(s) being monitored by t.

- The Kill(nil) performed by goroutine 1 won't affect the value
  of t.reason due to the logic in the Kill method (although,
  observing the memory model pedantically means goroutine 1 might
  do whatever it pleases with the memory region, due to lack of
  synchronization).

In a different scenario, though, t.Kill in goroutine 1 might be
performed with a non-nil error, and goroutine 2 would see either
nil or the error, and t.reason might be in an intermediate unknown
state, so the race is in fact real. Solving this specific race via
a mutex, as done in this change, still won't mean that this
behavior is sane, though: what t.Wait() in goroutine 2 observes
will be either the prior error value, or the new error value,
based purely on timing of the two Wait calls.

The change introduced protects t.reason with the tomb's mutex,
which silents the race detector, and makes the logic entirely
memory-model friendly.

16. By Gustavo Niemeyer

Added link to Roger's multi-goroutine example.

15. By Gustavo Niemeyer

Fixed a couple of typos.

14. By Gustavo Niemeyer

Added ErrDying. Renamed ErrStillRunning to ErrStillAlive.

R=TheMue
CC=
https://codereview.appspot.com/5981052

13. By Roger Peppe

tomb: update API

- Rename Fatal and Fatalf to Kill and Killf.

- The Stop error value is gone. Use nil now.

- Err will now return ErrStillRunning if the goroutine isn't dead
  yet, which means a nil return reflects an actual nil Kill call.

- Make zero-value of Tomb good to use, and as a consequence, make
  Dead and Dying into methods rather than fields.

R=niemeyer
CC=
https://codereview.appspot.com/5755055

12. By Gustavo Niemeyer

Ported to current weekly.

11. By Gustavo Niemeyer

Fixed typo in Done doc.

10. By Gustavo Niemeyer

Clarified doc for Fatal.

9. By Gustavo Niemeyer

Simplified doc for Err.

Branch metadata

Branch format:
Branch format 7
Repository format:
Bazaar repository format 2a (needs bzr 1.16 or later)
This branch contains Public information 
Everyone can see this information.

Subscribers