Locks can make your code a little hard to read, and they're much slower than atomic variables.
So what I'm going to do is make this into an atomic integer.
And this as well.
Here I can say sample size is equal to a new atomic energy object.
With a value of zero.
We did the same thing over here.
And so by virtue of these variables being atomic, we can rest assured that if a second thread tried
to access it, it's kind of like, Oh, wait up, don't touch me just yet.
I'm being updated by one thread.
I'll get to you in a second.
It's pretty cool.
And here to increment an atomic variable, we're going to say sample size.
Darts ad and get.
We're going to add one more, say, quantity sold.
Don't add and get quantity.
We're on the Cote.
And our application is thread safe.
Perfect.