What If the Number of Add() and Done() Calls Differ?

Let’s learn how the number of Add() and Done() calls affect program behavior in Go with command-line parameters.

When the number of sync.Add() calls and sync.Done() calls are equal, everything is going to be fine in our programs. However, this may not always be the case. This lesson explores what happens when these two numbers do not agree with each other.

Number of Add() and Done() calls

Depending on whether command-line parameters exist or not, the presented program acts differently. Without any command-line parameters, the number of Add() calls is smaller than the number of Done() calls. With at least one command-line parameter, the number of Done() calls is smaller than the number of Add() calls.

Coding example

You can go over the Go code of addDone.go on your own. For now, the important thing is the output it generates. Running addDone.go without command-line arguments produces the following error message:

Get hands-on with 1200+ tech skills courses.