The WaitGroup Documentation <https://pkg.go.dev/sync#WaitGroup> says " A 
WaitGroup must not be copied after first use.". 

You are passing around and calling choppingActivity by value, so it is 
being copied after Add() is called, and again each call to choppingAction() 
and choppingSimulation(). 

If you run "go vet" on your code it will alert you to the problems. 

On Friday, March 25, 2022 at 10:27:02 AM UTC-4 sunto...@gmail.com wrote:

> *Re-using the old thread for a new problem that I'm getting:*
>
> fatal error: all goroutines are asleep - deadlock!
>
> I rewrote my 
> https://github.com/suntong/lang/blob/master/lang/Go/src/sys/butchers.go 
> files from procedure based to OO based, as
> https://github.com/suntong/lang/tree/master/lang/Go/src/sys/butchersOO
>
> The two programs behaves exactly the same, however my new "OO" approach 
> ended with 
>
> fatal error: all goroutines are asleep - deadlock!
> goroutine 1 [semacquire]:
>
> The only reason that I can think of is that,
>
> I changed my goroutine calling from function calling of
> `go choppingProblem(i, knifeLeft, knifeRight)`
> (
> https://github.com/suntong/lang/blob/9057e5718e00d396d0fe9a232820bdb79a31df72/lang/Go/src/sys/butchers.go#L79-L82
> )
>
> to method calling of
> `go chopping.choppingAction(i, knifeLeft, knifeRight, &st)`
> (
> https://github.com/suntong/lang/blob/9057e5718e00d396d0fe9a232820bdb79a31df72/lang/Go/src/sys/butchersOO/main.go#L129-L132
> )
>
> Might that be the reason? 
> How to fix the problem?
>
> Thanks
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1e3d22ca-f4c0-4063-9fdf-6d6bdbcf3202n%40googlegroups.com.

Reply via email to