1
00:00:00,420 --> 00:00:04,800
Locks can make your code a little hard to read, and they're much slower than atomic variables.

2
00:00:05,100 --> 00:00:08,490
So what I'm going to do is make this into an atomic integer.

3
00:00:10,070 --> 00:00:10,820
And this as well.

4
00:00:14,860 --> 00:00:20,830
Here I can say sample size is equal to a new atomic energy object.

5
00:00:22,420 --> 00:00:23,620
With a value of zero.

6
00:00:28,120 --> 00:00:29,410
We did the same thing over here.

7
00:00:33,140 --> 00:00:38,750
And so by virtue of these variables being atomic, we can rest assured that if a second thread tried

8
00:00:38,750 --> 00:00:41,810
to access it, it's kind of like, Oh, wait up, don't touch me just yet.

9
00:00:41,810 --> 00:00:43,670
I'm being updated by one thread.

10
00:00:43,700 --> 00:00:44,930
I'll get to you in a second.

11
00:00:45,440 --> 00:00:46,100
It's pretty cool.

12
00:00:46,760 --> 00:00:54,050
And here to increment an atomic variable, we're going to say sample size.

13
00:00:55,260 --> 00:00:57,330
Darts ad and get.

14
00:01:00,360 --> 00:01:04,470
We're going to add one more, say, quantity sold.

15
00:01:06,490 --> 00:01:08,770
Don't add and get quantity.

16
00:01:15,600 --> 00:01:16,380
We're on the Cote.

17
00:01:23,200 --> 00:01:24,940
And our application is thread safe.

18
00:01:25,030 --> 00:01:25,600
Perfect.

