Created by Gustavo Niemeyer on 2011-10-09 and last modified on 2014-05-29
Get this branch:
bzr branch lp: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

Gustavo Niemeyer

Recent revisions

18. By Gustavo Niemeyer on 2014-05-29

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

17. By Gustavo Niemeyer on 2013-05-31

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:


and goroutine 2 is doing:


and goroutine 3 is doing:


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

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 on 2012-04-04

Added link to Roger's multi-goroutine example.

15. By Gustavo Niemeyer on 2012-04-03

Fixed a couple of typos.

14. By Gustavo Niemeyer on 2012-04-03

Added ErrDying. Renamed ErrStillRunning to ErrStillAlive.


13. By Roger Peppe on 2012-03-06

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.


12. By Gustavo Niemeyer on 2012-01-18

Ported to current weekly.

11. By Gustavo Niemeyer on 2011-10-23

Fixed typo in Done doc.

10. By Gustavo Niemeyer on 2011-10-23

Clarified doc for Fatal.

9. By Gustavo Niemeyer on 2011-10-23

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.