1
00:00:03,180 --> 00:00:10,940
So going back to our producer consumer 
idea here. 

2
00:00:12,280 --> 00:00:18,459
We're going to have a producer producing 
a value and a consumer consuming a value 

3
00:00:18,459 --> 00:00:24,915
but now we have two consumers. 
And let's say we guarantee sequential 

4
00:00:24,915 --> 00:00:29,102
consistency in our model. 
What breaks here? 

5
00:00:29,102 --> 00:00:33,349
Well, if we guarantee sequential 
consistency, and we have a reader excuse, 

6
00:00:33,349 --> 00:00:37,549
me, a producer and a consumer. 
That code sequence that I showed 

7
00:00:37,549 --> 00:00:40,264
originally actually works out pretty 
well. 

8
00:00:40,264 --> 00:00:44,089
Because we are not having any of those 
reordering of, let's say, this store and 

9
00:00:44,089 --> 00:00:47,470
like this read or something. 
We're not actually getting those 

10
00:00:47,470 --> 00:00:52,800
reorderings to happen, because sequential 
consistency has basically outlawed those. 

11
00:00:52,800 --> 00:00:56,800
But all of a sudden if we have two 
consumers. 

12
00:00:56,800 --> 00:00:59,394
And we go and stare at this piece of code 
carefully. 

13
00:00:59,394 --> 00:01:04,530
This is our original piece of code. 
One of the things that happens is they 

14
00:01:04,530 --> 00:01:10,265
check the head, 
pointer To see if it's equal to tall 

15
00:01:10,265 --> 00:01:14,668
which means something invaluable. 
And if two, process two threads or two 

16
00:01:14,668 --> 00:01:19,189
processees try to do that simultaneously, 
they are going to fall through at this 

17
00:01:19,189 --> 00:01:21,986
point. 
And what could happen, is they could both 

18
00:01:21,986 --> 00:01:28,693
try to read the same value. 
So let's say you actually have two 

19
00:01:28,693 --> 00:01:33,059
consumers, consumer one and consumer two 
that are interleaved and we just 

20
00:01:33,059 --> 00:01:37,724
basically do every other cycle executing 
every other instruction from the two 

21
00:01:37,724 --> 00:01:42,448
copies of this consumer code interleaved. 
And, what's going to happen is they're 

22
00:01:42,448 --> 00:01:45,960
going to read the same value out of the 
queue. 

23
00:01:45,960 --> 00:01:53,063
Well, we really don't want that. 
We want to somehow guarantee that this 

24
00:01:53,063 --> 00:02:02,862
block here happens while no other threads 
or processes are executing the same block 

25
00:02:02,862 --> 00:02:07,285
here of code. 
So we're going to introduce this notion 

26
00:02:07,285 --> 00:02:13,133
of locks and semaphores, and we'll talk 
more about it next time, but the basic 

27
00:02:13,133 --> 00:02:20,361
idea is that you have, 
something. Now, it could be a piece of 

28
00:02:20,361 --> 00:02:27,588
hardware or it could be a memory location 
which guards the execution of a critical 

29
00:02:27,588 --> 00:02:33,637
section or a piece of code. 
And you can either have those be such 

30
00:02:33,637 --> 00:02:39,469
that only one process or one processor 
can execute that piece of code at the 

31
00:02:39,469 --> 00:02:43,255
same time. 
That's mutual exclusion and that's, a 

32
00:02:43,255 --> 00:02:46,890
mutex. 
Or you can think of a more general notion 

33
00:02:46,890 --> 00:02:51,131
of a semaphore. 
Where you can have some number N, where N 

34
00:02:51,131 --> 00:02:55,070
processes can enter a critical section 
concurrently. 

35
00:02:55,070 --> 00:02:59,375
An example of that as I said before in 
class, why we want to do that, is let's 

36
00:02:59,375 --> 00:03:03,793
say you have two sets of resources. 
Like, two outbound queues on your network 

37
00:03:03,793 --> 00:03:06,254
card. 
And you have P processors and you want 

38
00:03:06,254 --> 00:03:08,938
two people to try to go use it at the 
same time. 

39
00:03:08,938 --> 00:03:11,790
But you don't care which two. 
But it can't be three. 

40
00:03:11,790 --> 00:03:16,208
You need something that's more general 
than just a mutex or a single-user lock. 

41
00:03:16,208 --> 00:03:19,899
Okay, so we're going to stop here and 
we'll talk more about locks and 

42
00:03:19,899 --> 00:03:23,310
semaphores including hopefully some 
people speak Dutch. 

43
00:03:23,310 --> 00:03:27,224
Because that's, because we need to know 
that to get the names of some of these 

44
00:03:27,224 --> 00:03:27,840
semaphores. 

