If Waitgroups and Mutex always needs to be passed by reference always, can't we make it a reference type (forbid the use of them as pass by value)? I mean is there any use case where we need to use them pass by value?
When you pass any argument as value, the value will get copied. Any modification these arguments will be local the the func
. When the func
exits those changes will be gone.
In case of a WaitGroup
or Mutex
you do not want this, as you want to share the state. If all modifications were local, you could not sync anything, as you would have many different copies with different states.
One valid case could be that you want to copy a WaitGroup
or Mutex
, but that would be very implicit code and hard for another developer to understand/maintain.