From 8f598dd79e1a663ff778cbf69e5bed4bea428f9a Mon Sep 17 00:00:00 2001 From: Mark Peppers Date: Sun, 28 Sep 2025 12:37:03 -0400 Subject: [PATCH] Fix race condition Both Alice's and Barbara's "attempts" are now printed. --- .../livelock/fig-livelock-hallway.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/an-introduction-to-concurrency/why-is-concurrency-hard/deadlocks-livelocks-and-starvation/livelock/fig-livelock-hallway.go b/an-introduction-to-concurrency/why-is-concurrency-hard/deadlocks-livelocks-and-starvation/livelock/fig-livelock-hallway.go index 168471d..8dd9f8c 100644 --- a/an-introduction-to-concurrency/why-is-concurrency-hard/deadlocks-livelocks-and-starvation/livelock/fig-livelock-hallway.go +++ b/an-introduction-to-concurrency/why-is-concurrency-hard/deadlocks-livelocks-and-starvation/livelock/fig-livelock-hallway.go @@ -40,8 +40,8 @@ func main() { tryRight := func(out *bytes.Buffer) bool { return tryDir("right", &right, out) } walk := func(walking *sync.WaitGroup, name string) { var out bytes.Buffer - defer func() { fmt.Println(out.String()) }() defer walking.Done() + defer func() { fmt.Println(out.String()) }() fmt.Fprintf(&out, "%v is trying to scoot:", name) for i := 0; i < 5; i++ { // <1> if tryLeft(&out) || tryRight(&out) { // <2>