WEBVTT 1 00:00:30.180 --> 00:00:38.370 William Cheng: Okay, this is the live lecture for so anyone has any questions, please feel free to unmute yourself and ask questions. 2 00:00:54.270 --> 00:00:54.750 William Cheng: Anybody 3 00:01:29.940 --> 00:01:31.650 William Cheng: Hello. Can anybody hear me. 4 00:01:41.580 --> 00:01:42.450 William Cheng: Okay, thank you. 5 00:01:44.550 --> 00:01:45.960 William Cheng: anyone has a question. 6 00:02:14.520 --> 00:02:14.820 William Cheng: Oh, 7 00:02:44.550 --> 00:02:46.410 William Cheng: What is the microphone still muted. 8 00:02:49.890 --> 00:02:52.950 William Cheng: Somebody says, I am unable to hear me. 9 00:02:54.420 --> 00:02:55.920 Andrew Strimaitis: The microphones don't need it anymore. 10 00:02:56.610 --> 00:02:58.170 William Cheng: Oh, it's working. Okay, great. Thank you. 11 00:03:00.180 --> 00:03:01.650 William Cheng: Anyone has any question. 12 00:03:18.120 --> 00:03:23.640 William Cheng: Okay I think someone still said that they cannot hear me, I think you should be working now. Okay, anyways. 13 00:03:33.150 --> 00:03:36.000 William Cheng: No lecture for is perfectly understandable. 14 00:03:39.120 --> 00:03:41.280 William Cheng: I mean sometimes these are you know hard concepts. 15 00:04:21.210 --> 00:04:23.220 Andrew Strimaitis: I have a brief question about warm up one 16 00:04:23.790 --> 00:04:24.270 William Cheng: Okay, sure. 17 00:04:24.690 --> 00:04:31.260 Andrew Strimaitis: Anything. Um, so I remember reading in the instructions that when we made our warm up one file. 18 00:04:32.070 --> 00:04:41.940 Andrew Strimaitis: The purpose was to convert the list test file and then basically make edits to the main function to make your warm up one and there was a comment there about how 19 00:04:42.630 --> 00:04:48.870 Andrew Strimaitis: Part of this was because some of the functions you included would be useful later on. And then in parentheses. It's still like bubble sort, okay. 20 00:04:49.380 --> 00:04:59.880 Andrew Strimaitis: Um, so, for when it came down to actually sorting. Everything is it okay if we just leave the bubble sort, or any algorithm we possibly take from this test to just leave it in the code. 21 00:05:01.110 --> 00:05:03.720 William Cheng: If you don't use it. You should delete them. 22 00:05:04.500 --> 00:05:07.620 William Cheng: But it's okay, it's okay to also just leave it leave them in there. 23 00:05:09.330 --> 00:05:11.400 Andrew Strimaitis: And just comment that this is from your list us 24 00:05:11.610 --> 00:05:21.480 William Cheng: Yeah, but be careful. Yeah. Because what happens that when you leave a function there you don't use it. And we try to compile, you might get compiler warnings, the grading guidelines says he would get Kampala one, you gotta get points deducted 25 00:05:22.080 --> 00:05:27.060 Andrew Strimaitis: So it's okay for us to make minor edits to one of your function, just so it works for our warm up one code. 26 00:05:27.270 --> 00:05:31.500 William Cheng: What you're supposed to change it because I think the way it is. It probably doesn't work. 27 00:05:31.620 --> 00:05:32.280 Andrew Strimaitis: Right, right. 28 00:05:32.610 --> 00:05:39.990 William Cheng: Yeah, so, you know, the instructions that is there for people who are not familiar with how to create your first program. 29 00:05:40.680 --> 00:05:53.250 William Cheng: So I said, you know, you stop and list, as I see it, just, you know, copy it into one by one. I see people sort of know how to create their own program. They can just, they can just start from scratch. Okay, so, so you can do it any way you want. 30 00:05:53.880 --> 00:05:55.380 William Cheng: That was just one recommendation. 31 00:05:56.520 --> 00:05:56.820 Andrew Strimaitis: Thank you. 32 00:05:57.180 --> 00:05:57.420 Okay. 33 00:06:02.160 --> 00:06:03.120 Hardik Mahipal Surana: Good morning, Professor. 34 00:06:03.390 --> 00:06:08.880 Hardik Mahipal Surana: Morning. I had a question in chapter two. Slide number 16 35 00:06:10.500 --> 00:06:12.480 William Cheng: So which lecture is this, this is 36 00:06:12.870 --> 00:06:15.840 Hardik Mahipal Surana: I think lecture for itself. 37 00:06:18.030 --> 00:06:19.620 Hardik Mahipal Surana: Let me just say 38 00:06:22.830 --> 00:06:23.550 William Cheng: Okay, which 39 00:06:23.610 --> 00:06:24.840 Hardik Mahipal Surana: Yeah, this one, this one, 40 00:06:25.260 --> 00:06:25.980 William Cheng: This is the one. Okay. 41 00:06:26.130 --> 00:06:31.950 Hardik Mahipal Surana: So the question is, actually, with respect to creation of these different stacks basis for each thread. 42 00:06:33.120 --> 00:06:35.850 Hardik Mahipal Surana: Based on the image I see over here, I see that 43 00:06:37.410 --> 00:06:46.260 Hardik Mahipal Surana: On top of the current stack frame which the stack frame which creates the threads and has the preset underscore create function in it. 44 00:06:47.010 --> 00:06:57.390 Hardik Mahipal Surana: If we create multiple threads of we are creating new stack spaces above the current stack frame rate and we are allocating some space some fixed amount of space for each turn right. 45 00:06:57.660 --> 00:07:04.440 William Cheng: So okay, so, so I'll preface my just want to clarify. Okay. So I mentioned before, what the address space look like is determined by the compiler. 46 00:07:04.980 --> 00:07:12.180 William Cheng: So. So the basic idea is that you're going to create a static space inside your address space exactly where it is. It's not that important. 47 00:07:13.440 --> 00:07:13.800 Hardik Mahipal Surana: Okay. 48 00:07:14.700 --> 00:07:20.550 Hardik Mahipal Surana: So my question is by is there like a default amount of space that we allocate to each thread. 49 00:07:20.880 --> 00:07:22.710 William Cheng: Yeah, that's operating system dependent 50 00:07:23.430 --> 00:07:33.330 Hardik Mahipal Surana: Okay, and what happens when that stack space becomes full if we do, let's say, a recursive function call within the trade and the calls 51 00:07:34.440 --> 00:07:39.090 Hardik Mahipal Surana: There are so many calls at the taxpayers get exceeded compared to what is allocated to it. 52 00:07:40.140 --> 00:07:41.490 Hardik Mahipal Surana: generally happens in that case. 53 00:07:41.640 --> 00:07:49.590 William Cheng: Yeah, that's like divide by zero. That's like segmentation fault. So when you have a stack overflow. You also trapped into the operating system, the operating system will kill your program. 54 00:07:51.630 --> 00:08:02.490 Hardik Mahipal Surana: Okay, so is there any way for us to know, you know, when there is a chance that our stack for the thread might overflow or how would, what would be the best way for us to avoid that situation. 55 00:08:02.670 --> 00:08:10.650 William Cheng: Well, so let's say you read a recursive call to compute factorial. Right. Okay. And then you try to compute the factorial of a billion. 56 00:08:11.880 --> 00:08:15.360 William Cheng: Okay, so in that case, you know, it is really, it's really data dependent right 57 00:08:16.410 --> 00:08:24.870 William Cheng: If you, if you use the same function to computer factorial three, there's no problem. But if you use the same function to compute the factorial have a billion. Well, that is going to overflow. 58 00:08:25.710 --> 00:08:38.400 William Cheng: Today. So, you know, so there's nothing wrong with your, with your function is just that depends on your data. If you pass in some kind of a, you know, data that will cause recursion to go crazy. Then in that case, there's no address space is going to be big enough. 59 00:08:39.930 --> 00:08:41.250 Hardik Mahipal Surana: Okay, no. So got 60 00:08:42.570 --> 00:08:52.950 Hardik Mahipal Surana: it okay if we explored the edge cases over here where the input might be just to humongous. If we take a realistic sense where there might be a chance that dispatch taxpayers gets overflow. 61 00:08:54.660 --> 00:09:09.930 Hardik Mahipal Surana: What do we do in that sort of situation are we as programmers responsible to ensure that the the thread should not have a stack overflow or does the operating system also help us in some way that if we go beyond what is allocated towards does a delegator some more stack space. 62 00:09:10.680 --> 00:09:25.950 William Cheng: A note. It's really up to you. You are the program or you should know how much stacks basically going to use. Okay, so what happened is that, you know, if somebody asked you to say I want to compute, you know, the Factorial. Factorial of a billion. You say, Oh, I'm not going to do it. 63 00:09:26.670 --> 00:09:28.950 William Cheng: You know, because you know that's going to blow up your stack space. 64 00:09:29.190 --> 00:09:40.200 William Cheng: Okay, okay. So I think later on in chapter two. You know, like, you know, this argument right here. The second argument. Peter create there's a way to specify how big of a stack space that you want. 65 00:09:41.070 --> 00:09:50.880 William Cheng: Okay, so if you know that you know that the child thread that the charter that you create over here will need a bigger stack space. What then in that case you can call Peter great with a bigger stack space God 66 00:09:51.060 --> 00:09:58.110 William Cheng: But if you ask for too much. What then Peter Korea will fail because the opposite, you know, the Peter library says, I don't have that much space for you. So therefore you will fail. 67 00:10:00.270 --> 00:10:15.240 William Cheng: Okay, so, so, at some point, you know, if you really, really need a really big desktop space. Maybe you have to go to a 64 bit CPU, you know, because 32 bit address space is only a four gigabytes just not big enough for us. Or maybe you have to go to a 64 bit you know operating system. 68 00:10:16.290 --> 00:10:16.530 William Cheng: Okay. 69 00:10:16.830 --> 00:10:17.820 Hardik Mahipal Surana: Thank you. Okay. 70 00:10:18.390 --> 00:10:23.340 William Cheng: Yeah, because if you have a 64 bit operating system. Right. The size of the address space is going to be, you know, like to, to the 64 71 00:10:23.970 --> 00:10:34.620 William Cheng: So I think, you know, some of the criticisms are two 364 is too big, nobody that needs that big. So they will limit the size of the address space to be two to the 48 okay so that's that's still a pretty big number. 72 00:10:35.760 --> 00:10:37.620 Hardik Mahipal Surana: Okay, thank you. Yeah. 73 00:10:37.680 --> 00:10:38.070 William Cheng: You're welcome. 74 00:10:40.800 --> 00:10:43.890 William Cheng: Yeah, so I just want to make another comment to say that, you know, there's, um, 75 00:10:44.790 --> 00:10:48.930 William Cheng: You know, you need to know what you're dealing with. When you read your program right you know 76 00:10:50.070 --> 00:11:02.670 William Cheng: If the number that you're using. You just too big. And if you do some calculation on the back of the envelope and you say, oh, wow, you know, even with a 48 bit address space. I won't be able to run this program one then then then you know it's not gonna work. 77 00:11:03.240 --> 00:11:10.320 William Cheng: Okay, the optimism is not there to provide any kind of Matt and kind of a magic solution when you try to use up too much of your address space. 78 00:11:18.510 --> 00:11:20.940 William Cheng: Any other people have questions. 79 00:11:24.660 --> 00:11:26.460 Chao Xiang: Oh hi, Professor, can you hear him. 80 00:11:27.630 --> 00:11:28.500 William Cheng: Yes. Yeah, I can hear you. 81 00:11:29.190 --> 00:11:32.550 Chao Xiang: Yeah, I have a question on pause a piece shred joining in. 82 00:11:33.570 --> 00:11:36.240 Chao Xiang: Tended to slide in the slides 22 83 00:11:37.290 --> 00:11:47.160 Chao Xiang: So the first question is, can we can have some stress like joining oneself like cold calling myself spread ID. 84 00:11:47.910 --> 00:11:53.370 William Cheng: Yeah, so that's a, you know, I think that's going to be have is going to have unpredicted behavior. 85 00:11:54.870 --> 00:12:05.580 William Cheng: So it's probably not a good idea. Anyways, you know, you should go with a basic definition is that you want to wait for another third that to die if you want to wait for yourself to die. Well, then I will never happen. 86 00:12:06.600 --> 00:12:28.230 Chao Xiang: Yeah, and they can you give an example of like to shreds. Want to join with the same thread. So is that mean two different shreds and core piece read joining of same thread or like one thread called two different piece read joining in the same program. 87 00:12:28.620 --> 00:12:30.360 Chao Xiang: Yeah, so the situation. 88 00:12:30.930 --> 00:12:38.640 William Cheng: Ah, yeah. So, you know, usually that doesn't happen. You know, so, so it's really something things that we shouldn't worry about 89 00:12:39.120 --> 00:12:44.070 William Cheng: But some people you know so. So for example, if your warm up to right, you're going to end up with the main thread plus four threads. 90 00:12:44.790 --> 00:12:50.490 William Cheng: So who's going to join with whom right so so if you use global variable, you have to throw identifier for all these five threats. 91 00:12:50.970 --> 00:12:58.890 William Cheng: Okay, so, so, so I guess what you can do that. You can have, you know, two, three. I tried to join with the same thread. But in that case the behavior is going to be unpredictable. 92 00:13:01.560 --> 00:13:02.010 Chao Xiang: Okay. 93 00:13:02.250 --> 00:13:07.230 William Cheng: I mean, I don't have any reason why anybody wants to do that but you know so. So typically, the programming, but 94 00:13:09.540 --> 00:13:18.120 Chao Xiang: OK, so once it cannot be called in pre piece read twice in the whole process right 95 00:13:18.540 --> 00:13:20.760 William Cheng: Can I be because people join 96 00:13:21.450 --> 00:13:24.720 Chao Xiang: Yeah, can be caused by piece rejoicing twice. 97 00:13:25.650 --> 00:13:33.120 William Cheng: So, so let's say you have three threads of your A, B and C. Right. Okay. So they all know about the three identifier for each other. Right. So if a copy 98 00:13:33.210 --> 00:13:42.660 William Cheng: Or a joint for CBS call a piece or john for see. So in that case, you know, to thread, try to join with the same threat. Okay, so when when this thread dies. 99 00:13:43.080 --> 00:13:49.350 William Cheng: It's going to join with one of them. But then if the other thing I tried to join with it. Then, then it's undefined. Right. The behavior is going to be undefined. 100 00:13:50.250 --> 00:13:56.610 William Cheng: Oh, because this thread is already dead. Right. So the three identify it become meaningless. So in that case, what will happen, why nobody knows. 101 00:13:59.520 --> 00:14:03.360 Chao Xiang: So this is to prevent circulate wiki like 102 00:14:03.780 --> 00:14:16.890 William Cheng: No, no, no, this is, this is just a programming bug, right. So for example, you know what you call Matt, what we call Malik Malik would be returned to your pointer. Sometimes, some people have a bug in the code to try to free the same point or twice. 103 00:14:18.150 --> 00:14:25.980 William Cheng: Okay, free the same pointer to why it's a programming bug and the second time when you free it you know maybe a program will crash, maybe a program will not crash. Nobody knows. 104 00:14:26.610 --> 00:14:36.000 William Cheng: Okay, so this is the same same situation. You know when you join with a threat threat should be, you know, as a threat should be joined only once. But if you join it twice, then nobody knows what's going to happen. 105 00:14:37.560 --> 00:14:38.490 Chao Xiang: Okay. Okay. Thank you. 106 00:14:38.760 --> 00:14:38.970 Yeah. 107 00:14:53.220 --> 00:14:55.800 Lalit Gupta: So I have a question regarding the joint on so 108 00:14:56.070 --> 00:14:59.070 Lalit Gupta: Okay. So, suppose I mean tired and it like 109 00:15:01.980 --> 00:15:06.750 Lalit Gupta: Create from the main here said we create like city to move more tracks. 110 00:15:07.410 --> 00:15:08.370 Lalit Gupta: How is it okay 111 00:15:09.030 --> 00:15:12.690 Lalit Gupta: So from the main thread. We create three more threads. 112 00:15:12.840 --> 00:15:13.170 Okay. 113 00:15:14.580 --> 00:15:20.400 Lalit Gupta: So is it okay to join these details into the main a main file mean 114 00:15:22.920 --> 00:15:38.730 William Cheng: Yes. So let's go back to, you know, the original code that we have over here. Alright guys, so this code over here, recreate 100 child threat. Yeah. So one of the things that you're supposed to do, is that before this function return you should join with all these 100 threads. 115 00:15:42.300 --> 00:15:53.760 William Cheng: Okay, so, so I mean this code doesn't work right because over here. The three identify, we only keep track of one of them. So if you call peace or three or 100 time what, in the end, that the three identify it will be only this or identifier for the last threat. 116 00:15:54.270 --> 00:16:08.250 William Cheng: Okay, so in order for you to join with all 100 thread. Maybe she is an array over here of 103 identifier. Right. So in the end, after you create all these threads, then the mainstream with join with all them well after you finish joining with all of them that you can return from this function. 117 00:16:10.320 --> 00:16:18.630 William Cheng: Okay. So typically when you try to create threat. That's what you would do. Okay. So, for example, in your warm up to your warm up to your main so it's going to create these for child threat. 118 00:16:18.960 --> 00:16:23.430 William Cheng: After the mainstream create these for Chelsea. What is the main thing that's going to do well. The main site has nothing to do 119 00:16:23.970 --> 00:16:29.670 William Cheng: Okay, so therefore the main so she just create this for childcare and just join with you know all four of them. 120 00:16:30.300 --> 00:16:39.210 William Cheng: When, when it finished joining with all these child threats that he knows that nobody else is running. So therefore, the main thread. In this case, they can actually print statistics or do whatever he wants. 121 00:16:40.710 --> 00:16:41.130 Lalit Gupta: Okay. 122 00:16:41.340 --> 00:16:57.120 Lalit Gupta: So okay, so this is this is doing this is like a is a right way to do it. But what you're saying what you're saying. Previously, it's like if you have to child child. The child does not do or should not join with the other child turd. Right. 123 00:16:57.390 --> 00:17:03.600 William Cheng: Well, it depends on how you write your code. So again, the PISA. Let me just give you a bunch of tools of how to create us how to, you know, do 124 00:17:04.080 --> 00:17:18.390 William Cheng: All the stuff and then it's up to you to to organize your threat right so you can actually have one parents right over here. So let's recreate to chat threads. A and B over here. Right. Okay. And then A is going to create a C and D right and then p is going to create E F and G. 125 00:17:19.560 --> 00:17:29.760 William Cheng: Okay, so then, in this case, who should join with whom. What, then, again, it's up to you. Right. So, so one, one obvious way to do it will be when a create C and D, a way for see Andy 126 00:17:30.000 --> 00:17:34.860 William Cheng: Where is going to join with C and D. So there's this way was end finishes or then a can continue 127 00:17:35.100 --> 00:17:47.670 William Cheng: Right, similarly be over here be create E F and G. So typically what you will do is that be after you create you have n g p will join with the FR E F and G. Okay, when they finished running over here. What then we can continue to do what he was doing. 128 00:17:48.840 --> 00:17:55.290 William Cheng: Will continue to do what it's supposed to do. So maybe what it will do is that we will create, you know, H, I, J, or something like that. 129 00:17:55.830 --> 00:18:03.450 William Cheng: So you need to sort of figure out how you want to create all these threads and how do all these threads going to interact with each other. And also, how does one stay away for other side to die. 130 00:18:04.470 --> 00:18:06.300 William Cheng: Okay, the programmer has this choice. 131 00:18:08.520 --> 00:18:13.710 Lalit Gupta: But you're saying is making sense but like I wonder, understand what is not the right practice. 132 00:18:15.540 --> 00:18:24.120 William Cheng: Not the right practice. I don't know. I only. So typically, what I do is I sort of teach you know what is the right way, the right way to do stuff. 133 00:18:25.290 --> 00:18:33.480 William Cheng: If you know what the right way to do stuff and you know you should try it, you should you should try to do things that that way if it doesn't work, then we should talk about it. 134 00:18:34.230 --> 00:18:41.370 William Cheng: Okay. Some people will maybe look for stuff on the internet and then maybe there are plenty or wrong way to do things on the internet. I, I don't really know. 135 00:18:43.080 --> 00:18:50.280 Lalit Gupta: Okay, we got an invite on the slide, you were saying you should not try to join charts like this. So I 136 00:18:50.310 --> 00:18:52.920 William Cheng: Wish and I tried to join threats like what yeah 137 00:18:53.280 --> 00:18:57.870 Lalit Gupta: Don't like in the previous slide was asking the question. 138 00:18:58.320 --> 00:18:58.650 William Cheng: Okay. 139 00:18:58.680 --> 00:19:01.740 Lalit Gupta: Not able to understand, like, what exactly you're trying to say. 140 00:19:02.160 --> 00:19:06.120 William Cheng: Oh, so you have 3am three A, B and C. Right, so 141 00:19:06.150 --> 00:19:08.940 William Cheng: He wants to wait for see to die. So a join with dressy 142 00:19:10.020 --> 00:19:14.790 William Cheng: Okay, so the question is, what it be also want to join with you. I see. Well, then it doesn't work. 143 00:19:15.840 --> 00:19:28.740 William Cheng: Right. Because over here as a I want to wait for see to die right so so the copies or joy be you know if he says, I also want to wait for it to die. What, then, then the logic doesn't make sense. Okay, so, so the the comment there is not to do that. 144 00:19:33.180 --> 00:19:35.400 Lalit Gupta: Does it make sense, yes. So 145 00:19:35.430 --> 00:19:41.220 William Cheng: Remember when you wait for a threat to die. What does that mean, right, that means that you want the the return exit code from this threat. 146 00:19:42.120 --> 00:19:54.540 William Cheng: Okay, so when a way for the first see to die. See, is going to be running, running, running at some point he's going to die when see dicey is going to return the value and that value is going to get returned in the argument of words that argument there. 147 00:19:59.010 --> 00:20:03.090 William Cheng: Okay, so let's take a look at P3 join over here. 148 00:20:04.650 --> 00:20:13.680 William Cheng: Right. So let's say you call this function right here you copies to a joy and then you provide the address of the Mexico. So if threat see dies over here. 149 00:20:14.130 --> 00:20:29.100 William Cheng: It's going to take the Mexico and return to the result. And now the the the control block of ice is going to get destroyed. Okay, so therefore if thread be also also joined with. I see. Well now, so I see doesn't exist anymore. So therefore, the behavior is going to be undefined. 150 00:20:30.330 --> 00:20:35.070 William Cheng: Okay, so you shouldn't write code like that if you understand what piece or joined us. 151 00:20:35.790 --> 00:20:41.100 William Cheng: Right piece or a joint says I want to wait for three C's to die. And I also want to return co found through it. 152 00:20:41.550 --> 00:20:54.360 William Cheng: Was so in that case, if you have two threads trying to wait for SCD diet and both of them want to return cover thread, see what that is not possible, right, be the third see can only return the the the return code only 213 and not to threats. 153 00:20:55.170 --> 00:20:55.680 Lalit Gupta: OK, yeah. 154 00:20:56.910 --> 00:20:57.210 William Cheng: OK. 155 00:21:00.060 --> 00:21:07.320 William Cheng: Yeah, it's the same thing with the example that we're using is Malik and free right when you Malik something you should call on call free on that address only once. 156 00:21:07.650 --> 00:21:15.030 William Cheng: If you, if you call free on a twice, then they're going to get into trouble. Right. So the question is, why would you free advice. Well, it's a programming, but 157 00:21:16.470 --> 00:21:23.760 Lalit Gupta: Yeah, I think. Yes. Because once you have your turn the value like the data structure of that terrible should 158 00:21:24.150 --> 00:21:26.790 William Cheng: This this data structure will be gone. Yeah. Yes. 159 00:21:30.660 --> 00:21:36.150 William Cheng: Okay, okay. Yeah. So, so the message over here is that you need. You need to understand exactly what piece we're joined us. 160 00:21:36.390 --> 00:21:46.500 William Cheng: And you've got to have a model your head to say, well, when do you actually copy the return Mexico to, you know, the threat that they wanted. And then once you do that, the second job block is gone. 161 00:21:46.770 --> 00:21:54.120 William Cheng: So next time when somebody joined with it is a while. How is that going to where it's not gonna work. Right. So once you get used to thinking like this then then then it all makes sense. 162 00:22:23.850 --> 00:22:24.090 Wookyum Kim: Oh, 163 00:22:26.340 --> 00:22:26.700 William Cheng: Yes. 164 00:22:28.110 --> 00:22:28.350 Wookyum Kim: Oh, 165 00:22:29.520 --> 00:22:30.180 Wookyum Kim: Seven. 166 00:22:31.980 --> 00:22:32.610 William Cheng: Slice seven 167 00:22:32.880 --> 00:22:33.270 Yeah. 168 00:22:42.570 --> 00:22:42.960 William Cheng: Okay. 169 00:22:44.280 --> 00:22:44.610 William Cheng: Yeah. 170 00:22:44.640 --> 00:22:48.870 Wookyum Kim: So here I'm 171 00:22:50.400 --> 00:23:03.390 Wookyum Kim: So, I mean, in the piece read create function. Oh, for the force arguments we are using the boy did pointer is a type caster case things right for the I 172 00:23:04.080 --> 00:23:07.050 William Cheng: The first the first argument. The for the for the last one. 173 00:23:07.080 --> 00:23:08.250 Wookyum Kim: Of course, yeah. The last one. 174 00:23:08.700 --> 00:23:13.740 William Cheng: The last one. The arguments voice right so if you use integer, you have to type cast the voice, Doc. Yeah. 175 00:23:14.220 --> 00:23:16.320 Wookyum Kim: Yeah, but I mean I'm i mean 176 00:23:16.440 --> 00:23:26.910 Wookyum Kim: For me, it is really unfamiliar to see the typecasting of the pointer have some things. I mean it is integers, but you're typecasting two 177 00:23:27.690 --> 00:23:28.920 Wookyum Kim: Boys pointer. Right. 178 00:23:29.190 --> 00:23:38.190 William Cheng: Right. So this works because voice start right so voiced are all it means on a 32 CPU is is a 32 the value right integer is a 32 bit value. 179 00:23:38.940 --> 00:23:39.870 Wookyum Kim: Okay, okay. 180 00:23:41.550 --> 00:23:44.910 William Cheng: So therefore, it's 32 to 32 bears, so it's okay. 181 00:23:46.020 --> 00:23:52.590 Wookyum Kim: Oh, but is it really safe true for our in Jenner us like just kinda 182 00:23:53.220 --> 00:23:57.330 William Cheng: Well, you need to know what you're dealing with. Right. You know if this is a 64 bit CPU. 183 00:23:57.660 --> 00:24:09.060 William Cheng: Yeah, then voice that will be 64 bit long. Right. Okay. In that case it integer is 32 bit you take a 32 bit you take a 32 bit number and you try to put it into a 64 bit number 184 00:24:09.480 --> 00:24:24.510 William Cheng: One. In that case, you know what happened to the leading 32 bit. So those are the question you have to answer. Right, so, so, so, so you got to do a very, very carefully, because if you put a 32 bit integer into a 64 bit voice star, then we don't really know what happened to the first 32 bit 185 00:24:26.190 --> 00:24:32.940 William Cheng: Okay, but if you are on a 32 CPU voice starts exactly 32 bit long one, then you know that it's before bed you copy from the integer 186 00:24:33.420 --> 00:24:36.420 William Cheng: To the, to the voice star. So, in that case, it's perfectly fine. 187 00:24:37.110 --> 00:24:45.390 William Cheng: I see. Okay, so, so actually what you can do is that, you know, if you have a virtual machine that 64 bit long. And then you compile, you know, CO like this on a virtual machine. 188 00:24:45.570 --> 00:24:51.690 William Cheng: On 64 bit virtual machine, you will see that you'll get a compiler wanting to say hey you know you know there's something wrong. 189 00:24:52.110 --> 00:24:53.550 Wookyum Kim: OK. OK, I got it. 190 00:24:53.670 --> 00:24:56.850 William Cheng: On a 32 bit of butter 16.04 then, then there's no problem. 191 00:24:57.180 --> 00:24:58.560 Wookyum Kim: Okay. Okay. Thank you. 192 00:24:58.800 --> 00:25:00.900 William Cheng: Yeah, you got to do this very carefully. Yeah. 193 00:25:01.230 --> 00:25:03.720 Wookyum Kim: Okay and slide. 194 00:25:03.780 --> 00:25:06.540 William Cheng: 2121 okay 195 00:25:11.310 --> 00:25:11.760 William Cheng: Yes. 196 00:25:12.330 --> 00:25:27.420 Wookyum Kim: So this is accident piece. Ready, said, I'm kind of confused. During the lectures about that. So in that in thread, then if we call exit than that even. The main functions and 197 00:25:28.920 --> 00:25:33.150 William Cheng: Yeah, so the exit is the system called right so you come inside the operating system. 198 00:25:33.360 --> 00:25:33.660 Wookyum Kim: Yeah. 199 00:25:33.690 --> 00:25:35.370 William Cheng: Then you kill the entire process. 200 00:25:36.540 --> 00:25:39.300 Wookyum Kim: Okay, so that means that are the are the 201 00:25:40.050 --> 00:25:44.820 Wookyum Kim: Things on the alert running or just to terminate. Right. 202 00:25:45.270 --> 00:25:52.320 William Cheng: Right, so, so it's a little complicated, right, because when you come inside the operating system. So let's say that we take the example of creating 100 threads. 203 00:25:52.350 --> 00:25:54.810 William Cheng: Right, so we're going to end up with 101 threads. Okay. 204 00:25:55.110 --> 00:26:01.140 William Cheng: One of them called exit. Okay, so, so, to try to kill the entire process so i don't i don't want the result anymore. I just want to quit the program. 205 00:26:02.070 --> 00:26:11.730 William Cheng: So what it will do is it will come inside the operating system. But what about the other 100 thread right the other 103 there might be running in 100 other CPUs simultaneously. 206 00:26:12.090 --> 00:26:14.490 William Cheng: Yeah, that case how do you actually kill the program. 207 00:26:16.260 --> 00:26:21.420 William Cheng: Okay, so, so it's a little tricky to actually implement exit correctly when there are multiple CPUs. 208 00:26:22.770 --> 00:26:28.440 William Cheng: Okay, but if there's only one CPU while you have one of the threads over here. Make the exit system call you come into the kernel. 209 00:26:28.620 --> 00:26:35.370 William Cheng: What are the other 100 threads doing well. They're all sleeping right because I don't have one CPU. If I only have one CPU, I can only do one thing at a time. 210 00:26:35.580 --> 00:26:40.620 William Cheng: And this thread is calling exit. Right. So, therefore, all the other threats are sleeping. Well, in that case, I can just kill all of them. 211 00:26:41.880 --> 00:26:43.800 Wookyum Kim: Okay, okay. 212 00:26:44.910 --> 00:26:56.460 William Cheng: I see. Yeah. So multiple CPU typically gets a little more complicated. Okay, thank you. Okay. Yeah. And when you called Pisa exit only the thread that cause it, that will be the only thread that ties. 213 00:26:56.880 --> 00:26:57.780 Wookyum Kim: OK. OK. 214 00:26:57.990 --> 00:27:00.000 Wookyum Kim: So if and if the 215 00:27:00.060 --> 00:27:04.020 Wookyum Kim: If we call the exit that are the artists are it will die right 216 00:27:04.680 --> 00:27:07.050 William Cheng: Yeah, all the other threat would would die. Yeah. 217 00:27:07.680 --> 00:27:08.820 Wookyum Kim: Okay, okay, but 218 00:27:08.940 --> 00:27:22.020 William Cheng: But, you know, so if you try to ask the question of exactly how they will die. Well then, then we don't know. Right. Because why because that the other throw running the other CPU. So at some point, we need to make sure that they are not running the CPU and then we can kill it. 219 00:27:23.250 --> 00:27:26.250 William Cheng: Okay, if a thread running inside the other CPU, there's no way to stop it. 220 00:27:27.120 --> 00:27:30.960 William Cheng: Okay, because if you're running one CPU you tell the other CPU to stop the other secret says 221 00:27:32.010 --> 00:27:33.960 William Cheng: The other CPU don't don't really care about what you're saying. 222 00:27:34.260 --> 00:27:34.890 Wookyum Kim: Okay. 223 00:27:35.310 --> 00:27:49.260 Wookyum Kim: So if that if if we just when you have the one CPU and are the persons are the thread will die. But if we have the vertical threat. I mean word processors, then the other thread. We don't know. Right. 224 00:27:49.320 --> 00:28:00.450 William Cheng: Well, yeah, we have to wave the offices and whenever I the obvious this is. Oh. The other thing I running the other CPU. So therefore, the obvious is a need to have a way to tell the other CPU to say hey you know you know 225 00:28:01.080 --> 00:28:02.340 William Cheng: I'm trying to process. 226 00:28:02.670 --> 00:28:02.970 Yeah. 227 00:28:05.760 --> 00:28:15.060 William Cheng: Yeah, the opportunities that is powerful. He knows what's going on in the your entire machine. So if you have you know 200 CPUs, the obvious isn't actually knows what the 200 CPUs are doing 228 00:28:15.600 --> 00:28:22.140 William Cheng: Okay, but just cannot tell once up to say hey you know the kill that thread, because there's no way to do that. 229 00:28:22.530 --> 00:28:23.520 Wookyum Kim: Okay, okay. 230 00:28:23.610 --> 00:28:28.350 William Cheng: Yeah because threads an abstraction of the CPU. So you can really kill a CPU so 231 00:28:29.010 --> 00:28:29.490 Okay. 232 00:28:32.310 --> 00:28:34.320 Wookyum Kim: And then slide 40 233 00:28:34.980 --> 00:28:36.690 William Cheng: Slide 40 okay 234 00:28:44.100 --> 00:28:44.490 William Cheng: Yes. 235 00:28:45.150 --> 00:28:56.730 Wookyum Kim: So one things I was really confusing here is that I'm like variable x in here, the variable inside me attacks. 236 00:28:57.180 --> 00:29:00.480 Wookyum Kim: Right. And he's that variable. He's not 237 00:29:01.710 --> 00:29:04.650 Wookyum Kim: He's not accessible by that others stripe. 238 00:29:06.300 --> 00:29:08.850 William Cheng: Know this is how you supposed to organize your code. 239 00:29:09.450 --> 00:29:20.010 William Cheng: Okay, so, so when you have x that's shared by multiple threads, you want to, you know, over here on the right hand side is just a notation right we draw this picture in our head on the piece of paper to remind ourselves that 240 00:29:20.130 --> 00:29:23.940 William Cheng: Nobody should access variable x unless they have the mutates locked 241 00:29:24.360 --> 00:29:25.530 Wookyum Kim: Okay, I got it. 242 00:29:26.460 --> 00:29:35.700 William Cheng: Right, so, so, so, so, so, so is it possible you have another thread over here says x equal to five. What you can do that, but your program is gonna be a program is not gonna work. 243 00:29:36.120 --> 00:29:37.080 Wookyum Kim: Okay, I got it. 244 00:29:37.410 --> 00:29:41.880 William Cheng: Okay, so you got to make sure that x equal to five is done inside the critical section then then it's OK. 245 00:29:42.420 --> 00:29:43.530 Wookyum Kim: OK. OK. 246 00:29:43.650 --> 00:29:49.350 William Cheng: OK. But again, these library just give you tools. If you use it incorrectly while they your progress not gonna work. 247 00:29:49.710 --> 00:29:50.280 Wookyum Kim: OK. 248 00:29:50.610 --> 00:29:58.410 William Cheng: OK, so we're starting to develop good habits by drawing this picture to remind us the relationship between all these different function call and all the stuff. OK. 249 00:29:58.470 --> 00:30:05.610 Wookyum Kim: So the only the new tax can like systematically blocks that others things to come inside. Right. 250 00:30:06.960 --> 00:30:15.150 William Cheng: Yeah yeah if you write code like this, right, you got, you know, you if you put the access of variable x inside the critical section. 251 00:30:15.420 --> 00:30:23.760 William Cheng: Right then you guarantee you one minute. Now you guarantee the piece or a library will guarantee that you know this code in this code, they are mutually exclusive. Okay. 252 00:30:24.240 --> 00:30:28.890 William Cheng: If mutual exclusion is what you want. One thing you should write your code. This way. Okay. 253 00:30:30.420 --> 00:30:32.430 William Cheng: Okay. Yeah. Thank you. 254 00:30:32.490 --> 00:30:32.700 Wookyum Kim: Yeah. 255 00:30:33.450 --> 00:30:36.600 William Cheng: You're welcome. Yeah, so warm up to. It's an exercise of doing something like that. 256 00:30:37.500 --> 00:30:38.340 Wookyum Kim: Okay, yeah. 257 00:30:39.240 --> 00:30:39.930 Wookyum Kim: Thank you very much. 258 00:30:40.440 --> 00:30:40.890 You're welcome. 259 00:30:43.350 --> 00:30:55.110 Hardik Mahipal Surana: Professor, I had a question with respect to creation of the new tax law you explain that when we create a new text. We also need to define with respect to what or which variable or the variable that is being shared. 260 00:30:55.380 --> 00:31:06.510 William Cheng: No, you don't have. You don't have to declare it, you have to make a clear in your mind. This is part of your program design. Okay, well, you will, we will try to share a variable, you said, well, which we attack. Should I use to share this variable. 261 00:31:07.020 --> 00:31:13.110 Hardik Mahipal Surana: Okay, so we don't need to explicitly show that a which variables are shared with respect to 262 00:31:13.620 --> 00:31:18.780 William Cheng: So, so, so, you know, you either draw a picture like this on a piece of paper or you draw this picture mentally 263 00:31:19.290 --> 00:31:24.510 William Cheng: Right. And then, you know, for this new tax you need to decide which variable go inside the serialization box. 264 00:31:25.590 --> 00:31:29.940 William Cheng: Okay, you can put all the sheer variable inside of civilization box that will work. 265 00:31:31.140 --> 00:31:32.400 William Cheng: Okay, and that's warm up to 266 00:31:33.840 --> 00:31:43.620 William Cheng: Warm up to says, you know, you only have one new tax. Okay. Everything that you want to share, you put it inside of civilization box. So you are not allowed to touch anything unless you have to meet tax law. 267 00:31:45.270 --> 00:32:02.760 Hardik Mahipal Surana: Okay, but if different threads are working on different variables or different parts of data, like for example, if you take warm up to, if the packet creating thread is working on Q1 and the servers which are servicing the packets are working on Q2. 268 00:32:04.110 --> 00:32:09.810 Hardik Mahipal Surana: Technically q1 and q2 can operate independently. Right. So while them in the same Unix 269 00:32:10.230 --> 00:32:16.200 William Cheng: Right. So, that is correct. So some people will try to write your code that way and I strongly discourage them to do that. 270 00:32:16.950 --> 00:32:27.300 William Cheng: Okay, because things going to get very, very complicated, right, because, because you know the the packet arrival threat will happen is that it's going to use Q1, but sometimes it will use q1 and q2. 271 00:32:29.880 --> 00:32:36.600 William Cheng: Okay, so therefore, how, how do you write your code, you know, to use two different new tasks to do something like that, then it's going to get a little tricky. 272 00:32:37.140 --> 00:32:37.410 Hardik Mahipal Surana: Okay. 273 00:32:37.830 --> 00:32:42.450 William Cheng: Okay, so even though there might be a way to do to get this done. And also, you know, the other problem is that 274 00:32:43.290 --> 00:32:50.700 William Cheng: That, that, you know, when you're moving these packets from one place to the other. You also need to print out these trace messages onto the screen. 275 00:32:51.180 --> 00:32:59.430 William Cheng: Okay, and then the timestamp of these trays messages they need to be correct. So if you use multiple new tax, you're going to end up with the trace message, they will be out of water. 276 00:33:00.420 --> 00:33:14.340 William Cheng: Okay. Okay. So the question is that how do you actually write your code to make sure that the output is perfect and also all the right things supposed to happen. My simple recommendation is to put everything into one serialization box. So this way will make a program, much easier to write 277 00:33:15.000 --> 00:33:21.000 William Cheng: Okay. Is it the most efficient way is probably not the most efficient way. But if you do it this way, it will be correct. 278 00:33:21.510 --> 00:33:21.780 Hardik Mahipal Surana: Okay. 279 00:33:22.350 --> 00:33:24.090 William Cheng: Okay, so, so in warm up to one of them. 280 00:33:26.040 --> 00:33:32.850 William Cheng: You're going to see me you know saying this over and over again that class Google group, we need to focus on correctness and not efficiency. 281 00:33:34.650 --> 00:33:42.720 William Cheng: Okay, so, so therefore you know everything, you know, you see the token bucket data structure. Everything is that a token buggers data structure, you need to put it inside of civilization box. 282 00:33:43.230 --> 00:33:51.360 William Cheng: What else do you need to put inside of civilization box. Well, also, everything else, right. Like, like if you print a standard out standard out should be in this position box. 283 00:33:51.780 --> 00:34:02.670 William Cheng: If you read the clock. The clock to be inside of civilization. Pause. Anything that you can think of their share by all these threads. They should all go into the search engine box. So if you want to use that you have to have new tax law. 284 00:34:04.140 --> 00:34:13.440 Hardik Mahipal Surana: Got it. And I think in the later slides. When we introduced some force you explained why sometimes mutates has become an overkill. Right. 285 00:34:15.000 --> 00:34:24.900 Hardik Mahipal Surana: So I am a little confused as to how the Wii and Wii functions work there. Because if I if I try building an analogy of the spectrum mutants, we say that 286 00:34:25.350 --> 00:34:31.920 Hardik Mahipal Surana: If there are multiple new Texas, which are waiting on a particular. So if there are multiple sets which are waiting for one new tax. 287 00:34:32.610 --> 00:34:45.630 Hardik Mahipal Surana: They would all be a part of a queue and they would be put to sleep within the new tax law function and in summer force. The reason we use them as because we don't 288 00:34:46.980 --> 00:34:47.250 Hardik Mahipal Surana: So, 289 00:34:48.450 --> 00:34:57.450 Hardik Mahipal Surana: That might work on different parts of the same data and they don't need to technically be locked. But how do these p and v functions, ensure that 290 00:34:59.460 --> 00:35:02.820 Hardik Mahipal Surana: Ensure the synchronization which mutates also provides 291 00:35:03.510 --> 00:35:06.720 William Cheng: Yeah, so, so that's actually in the next lecture and lecture five 292 00:35:08.100 --> 00:35:17.190 William Cheng: You know so. So one of the messaging lecture five is that, you know, we introduced center for because you know it's important application but center for has limited use 293 00:35:18.270 --> 00:35:23.640 William Cheng: Okay. So pretty much the only time the Center for is good for is if you have pipeline parallelism. 294 00:35:24.660 --> 00:35:32.700 William Cheng: Okay, so in the next slide. I'm going to sort of talk about what that looks like and and that will be the only case anybody she use, you know, 295 00:35:33.330 --> 00:35:43.110 William Cheng: She, she used force. Okay, so, so really depends on you know how you're supposed to work with each other if they work with with each other using a certain style. Well, then, said before is perfect. 296 00:35:43.710 --> 00:35:48.570 William Cheng: Okay, if they work with each other using a different style, then you probably shouldn't use them for 297 00:35:49.500 --> 00:36:01.410 William Cheng: Okay, so just like a warm up to our warm up to, you know, it's really not a pipeline parallelism one or two is a little bit complicated. Okay. So, therefore, you know, India. What we should do is that we should use the most general way to use 298 00:36:02.400 --> 00:36:08.610 William Cheng: to to to to to implement a garden command. Okay. We talked about garden command over here I all these garden command over here. Okay. 299 00:36:09.360 --> 00:36:15.690 William Cheng: The, the Center for is one very, very specific way of using, you know, using this kind of concurrency control. 300 00:36:16.650 --> 00:36:25.170 William Cheng: Well guys, most of the time we don't really need it, but it's a very popular application. So that's why I guess if people learn you know Java code or c++ code. 301 00:36:25.560 --> 00:36:37.590 William Cheng: They will be using center for because it's nice and easy to use. And also, you know, the way that you know people the way that thread communicate with each other sort of fits the model of the Center for 302 00:36:38.640 --> 00:36:46.110 William Cheng: Okay, so, you know, so, so, so basically I the area over here that you have one thing over here, another threat and this tried to send data, you know, to the other threat. 303 00:36:46.770 --> 00:36:57.360 William Cheng: Right. So in this case, how do you send data up on one side to the other. Well, maybe you can sort of think about is I have a conveyor belt over here I put the data on the conveyor belt. And the other thing over here. Pick it up. Well, that's exactly the example that we're going to see 304 00:36:58.710 --> 00:37:07.050 William Cheng: Okay, so in that case yeah 74 is actually perfect but you know when our warm up to it doesn't look like that. Okay. So, therefore, we shouldn't use things like some of 305 00:37:07.050 --> 00:37:16.530 William Cheng: Way to warm up to. Okay, so the bottom line over here is that we're going to sort of teach you some of the primitives over here and then you need to decide, you know what, what will you try to write your application. 306 00:37:17.040 --> 00:37:25.200 William Cheng: Given that you know that they're all these kind of different synchronization primitive, you need to choose one of them or you choose multiple of them in order for you to finish your program. 307 00:37:26.190 --> 00:37:30.060 Hardik Mahipal Surana: Okay, so if you take an example of let's say shirts. 308 00:37:31.230 --> 00:37:34.260 Hardik Mahipal Surana: And our Center for S is set to the value one. 309 00:37:35.610 --> 00:37:41.700 Hardik Mahipal Surana: So sorry. You said said to the value to that means at most two thirds can be within the critical section is there. 310 00:37:42.270 --> 00:37:44.070 Hardik Mahipal Surana: Yeah, so if he 311 00:37:45.810 --> 00:37:53.220 Hardik Mahipal Surana: So if all the three threads run, we will see that your first can be triggered by two of those threads and the central for value can go from two to zero. 312 00:37:53.610 --> 00:37:54.810 Hardik Mahipal Surana: So the third Ted 313 00:37:54.900 --> 00:38:06.210 Hardik Mahipal Surana: Comes and tries to implement PFS what happens to that, since it's cannot since it cannot change the value of as a further below zero. What happened to that. So it does go to sleep, or what does it 314 00:38:07.560 --> 00:38:13.770 William Cheng: Depends on the implementation. Okay, so, so, you know, so since this is pseudo code doesn't really tell you how to implement it. 315 00:38:14.190 --> 00:38:25.020 William Cheng: Okay, so it depends on how you want to implement it so you can sort of think about at this time I go to sleep. Okay, or it will keep trying and then when they keep trying keep seeing as equal to zero. So, therefore, it's not doing anything. 316 00:38:26.880 --> 00:38:27.090 William Cheng: Okay. 317 00:38:27.150 --> 00:38:40.020 William Cheng: So, so, so, so if you have that thread running on the CPU keep reading as keeping meeting as as going to be zero is going to be zero is going to be zero. So, that's all. Does it stay in an infinite loop. So that will just be us to become bigger than zero. 318 00:38:41.700 --> 00:38:45.390 Hardik Mahipal Surana: So if you're trans inner, inner, inner continuous loop is it doing Busy waiting there. 319 00:38:45.780 --> 00:38:52.080 William Cheng: Yes. Yeah, that's a busy waiting and it's gonna, you know, eat up the CPU is that eat up your batteries on your phone. So that's really bad. 320 00:38:53.250 --> 00:38:58.800 Hardik Mahipal Surana: Okay, so how does this actually work with respect to the Peter implementation. 321 00:38:59.640 --> 00:39:04.050 William Cheng: Yeah. So in the next lecture, we're going to see exactly how to implement this using new tax. 322 00:39:06.390 --> 00:39:06.930 Hardik Mahipal Surana: Okay. 323 00:39:08.100 --> 00:39:10.110 William Cheng: Yeah, so, so, so in the end, all you 324 00:39:10.140 --> 00:39:13.110 William Cheng: Need is basically new tax you don't really need some a force. 325 00:39:13.560 --> 00:39:14.610 Hardik Mahipal Surana: Okay, okay. 326 00:39:15.600 --> 00:39:24.210 William Cheng: Right so so again this is was invented, you know, in 1970s by Dykstra, you know, he wants to, you know, do you know synchronization. So he invented 327 00:39:25.620 --> 00:39:29.070 William Cheng: For a sort of show people this is one way you can do things. 328 00:39:29.910 --> 00:39:30.870 Hardik Mahipal Surana: Okay, now 329 00:39:31.320 --> 00:39:38.490 Hardik Mahipal Surana: If we take the use case that was earlier defined for us. And before that, if you have a large data structure like a linked list. For example, 330 00:39:38.730 --> 00:39:43.290 Hardik Mahipal Surana: And your and you can ensure that you are always operating on different parts of the link list. 331 00:39:44.910 --> 00:39:52.710 Hardik Mahipal Surana: In that case, is it possible for a new tax law to be applied on a subset of the list, instead of the entire list. 332 00:39:53.400 --> 00:40:00.030 William Cheng: And then you can, you know, so, so we draw this picture of the civilization box right and we put variable inside the civilization box. 333 00:40:00.330 --> 00:40:08.940 William Cheng: I mean, if you know the length of the link list and you can, you know, so one thing you can do is that you can have one new tags over here you put the beginning part of the limitless over here. 334 00:40:09.210 --> 00:40:17.970 William Cheng: And then, you know, another you know another meeting. So here's why. Here's me a text to you put the rest of the link over here in the other civilization box. 335 00:40:18.780 --> 00:40:31.710 William Cheng: That you know that will work if this can be done. Okay. But, but, but clearly this is going to be difficult, right, because if you have a linked list. What about the link links that go between these two. You know, the beginning part and the later part of the link us, where do you put that 336 00:40:32.970 --> 00:40:46.710 William Cheng: Okay, so, so you need to design your program. And then, you know, conceptually, put all these variable inside the civilization boss, if there's a way to do it, then I will be great. But if there's no, there was no way to do it. So maybe you need to redesign the structure of your program. 337 00:40:48.060 --> 00:40:52.080 Hardik Mahipal Surana: So overall, we can say that some of us have very limited use 338 00:40:53.130 --> 00:41:00.930 William Cheng: So center for is it is 740 is pretty much only good for the case where you have producer consumer problem. 339 00:41:02.040 --> 00:41:02.460 Hardik Mahipal Surana: I see. 340 00:41:02.580 --> 00:41:06.990 Hardik Mahipal Surana: So for every other case, which is more generic than this. We would prefer to use a mix. 341 00:41:08.310 --> 00:41:15.810 William Cheng: So personally, I would always use, you know, new tags, because if we learn how to use the next lecture, we're going to do something called the condition variable. 342 00:41:16.260 --> 00:41:23.280 William Cheng: Okay, so apparently if you use mutates and condition variable together you can implement any kind of a synchronization that you want. 343 00:41:24.450 --> 00:41:30.390 William Cheng: Okay, so you can use that to implement some affords you can implement other synchronization a primitive that we're going to talk about in the next lecture. 344 00:41:31.260 --> 00:41:43.770 William Cheng: But you know, that's all you need. Right, so, so, so in this class, I sort of want people to focus on just mute tags and condition variable, okay, because if you know how to use these two things perfectly. You can do anything you want. 345 00:41:46.590 --> 00:41:47.280 William Cheng: Okay, thank you. 346 00:42:04.830 --> 00:42:05.550 Chao Xiang: Hi Professor 347 00:42:05.820 --> 00:42:21.390 Chao Xiang: Hey, yeah. I have a question about the piece of the new tax law. So, and we can see from the slides that every locker is initialize the way the same variable wishes initialize 348 00:42:23.880 --> 00:42:36.720 Chao Xiang: Every variable is initiated by the initial idea. So how can the function distinguish the different lot by the address or how, how is the variable and change. 349 00:42:38.130 --> 00:42:39.150 Chao Xiang: During the launch 350 00:42:39.900 --> 00:42:53.250 William Cheng: Yeah so. So if you wanted to find different new tax rate CAN SAY MID quarter this right and then you say, Peace a meat AX T n two equals to the initial, initial Iser. I mean, the initial idea just like the value zero, right, because the sign anything go to zero. 351 00:42:54.930 --> 00:43:00.270 Chao Xiang: Also the function distinguish different to locker by address 352 00:43:01.830 --> 00:43:12.180 William Cheng: So, so. Okay, so, so, by the way. So, so let's say that you actually the statement right and i equals to zero. Right. Okay. What is it, what does this mean, right. This means that copy the value of zero into it. 353 00:43:12.570 --> 00:43:19.620 William Cheng: Okay, so later on. You say in j equal to zero you copy a zero into J. So now both i n g R zero 354 00:43:20.760 --> 00:43:31.410 William Cheng: Okay. It's not that they are sharing the zero. They just, they all have a different values over here as over here at new tech number one over here I initialize to this value and mute X number to initialize to exactly the same value. 355 00:43:32.610 --> 00:43:40.140 William Cheng: Okay, so, so I guess maybe what you can do is that you can actually try to look at the definition of peace me attacked initial Iser. This is actually a data structure. 356 00:43:40.710 --> 00:43:48.690 William Cheng: Okay, so if you think about new tax what's inside the new tax. All right. Let's take a look at the new tax over here, right, if we look at this picture over here. Okay. 357 00:43:49.620 --> 00:44:04.680 William Cheng: What's inside of a new text data structure. Okay. The meat is let me let me go back over here. Yeah. So the new tech data structure is P three new text tea and I mentioned before, if it's, you know, if you have a data structure and that would underscore te. That means that it's a data structure. 358 00:44:05.310 --> 00:44:10.530 William Cheng: Okay, so the data structure has multiple fields. So in this case, what you know what must be insulted me attacks. 359 00:44:11.070 --> 00:44:18.420 William Cheng: What must be inside of it has over here is going to be. There's going to be a cute. Okay, so you can think about the new tag actually contain my 42 lists. 360 00:44:18.930 --> 00:44:26.460 William Cheng: Okay inside mute hags over here. There's another thing that you need to do that, you need to have is that you need to remember whether the meeting is locked or not, guys, so therefore 361 00:44:26.760 --> 00:44:34.320 William Cheng: The way you should think about a new tax implementation, while we have a real talk about implementation. Yeah. But if you need to implement a new task he has to have at least two things. 362 00:44:34.650 --> 00:44:40.890 William Cheng: One is that it needs to have a Q and it also needs to have another integer to say or bit to say whether the new tax is locked or not. 363 00:44:42.000 --> 00:44:44.220 William Cheng: Okay. So, therefore, you know, what is this code over here. 364 00:44:45.510 --> 00:45:00.630 William Cheng: Okay, so this is going to be a data structure that has two fields in them. One of them is my for two lists. So my for two lists, you need to initialize it to be to be empty list. And then it's going to be followed by integer to say whether the matrix is locked or not. 365 00:45:01.890 --> 00:45:16.860 William Cheng: Okay, so if you try to look into the piece or a library and try to find the definition of peace when you take initialize or you will see that it's a data structure that allow you to initialize the metallics to go to initial state where it's not luck and also the muta excuse empty. 366 00:45:19.050 --> 00:45:29.970 William Cheng: So therefore, when you say NY equal to this value, what you're saying is that I want to initialize M one to be unlocked and it has it has empty mute IQ. And when you say empty equals to this. 367 00:45:30.630 --> 00:45:36.690 William Cheng: Again, the same thing you're saying that I want him to to be initialized to be unlocked and also he has an empty q&a 368 00:45:39.300 --> 00:45:44.460 William Cheng: So therefore, it's perfectly okay to say that I want to initialize and wanting them to to be to be initialized to the same state. 369 00:45:45.960 --> 00:45:47.340 Chao Xiang: Okay, thank you. Okay. 370 00:46:10.080 --> 00:46:11.700 William Cheng: Anybody else has any question. 371 00:46:13.680 --> 00:46:22.860 Wookyum Kim: Prefer professor. It's not about the lecture. But, I mean, I have some like some problem to gather that teammate so 372 00:46:23.460 --> 00:46:46.050 Wookyum Kim: Yeah, we already group of three people, but we want to one more person is a teammates and yeah we already sent the order emails to the order least I mean are the people in the list. And so I i mean i want to like ask to about can I like posts like kind of 373 00:46:47.010 --> 00:46:49.320 Wookyum Kim: In the cool groups about it like 374 00:46:49.590 --> 00:46:59.280 William Cheng: Yeah, I think I mentioned before, you can use class Google group to, you know, ask people to join your group. Introduce yourself or whatever you want. You know, so it's perfectly okay 375 00:47:00.150 --> 00:47:00.480 Wookyum Kim: Okay. 376 00:47:00.840 --> 00:47:11.190 William Cheng: You can tell people that you have, you know, you have three. The three people you're looking for the fourth and you can use high school group for any kind of a, you know, class communication that that's perfectly fine. 377 00:47:11.820 --> 00:47:12.630 Wookyum Kim: Okay, thank you. 378 00:47:12.900 --> 00:47:17.010 William Cheng: Yeah, if you start using something inappropriate. I'm going to say that, hey, you shouldn't they shouldn't do that because 379 00:47:17.160 --> 00:47:18.420 William Cheng: Otherwise, all these things are fine. 380 00:47:18.930 --> 00:47:19.770 Wookyum Kim: Okay, thank you. 381 00:47:20.130 --> 00:47:20.490 Okay. 382 00:47:24.180 --> 00:47:28.710 Hardik Mahipal Surana: Small doubt with respect to the warm up with their another lecture based questions. Can I ask 383 00:47:29.190 --> 00:47:38.100 William Cheng: Yeah, of course. Yeah. So, so during the live lecture, you can ask me about the you know the recorded, you know, electro video. You can also ask me about programming assignments. No problem. 384 00:47:38.760 --> 00:47:46.590 Hardik Mahipal Surana: Okay, so I was I just started going through the spec for warm up to and I was a little confused with respect to the different rates that were 385 00:47:46.890 --> 00:48:01.080 Hardik Mahipal Surana: Mentioned well lambda or an interview. So I wanted to understand what do these rates actually mean is it that the packets should come at a fixed rate of after like like lambda seconds or what does that actually mean 386 00:48:01.560 --> 00:48:07.350 William Cheng: Yeah, so it's related to this picture, I had this picture, you know, on the left hand side, it tells you what land is 387 00:48:08.460 --> 00:48:21.600 William Cheng: Right on the left hand side over here. I guess I can't highlight this as over here, the rate. So, so if you're running in the deterministic mode. Okay, then the package arrived, the variable rate for the pack is going to be. It's going to be lambda 388 00:48:22.860 --> 00:48:27.960 Hardik Mahipal Surana: Okay, so, so that means that every lambda seconds. We have one packet arriving 389 00:48:28.800 --> 00:48:39.810 William Cheng: So for our warm up to it doesn't mean that. So, so what it means is that one over lambda is the entire packet arrival is the inter inter packet arrival time 390 00:48:41.970 --> 00:48:47.640 Hardik Mahipal Surana: Could you please elaborate more on that. What does that exactly mean like with an example. Probably two packets or something. 391 00:48:47.910 --> 00:48:51.900 William Cheng: Yes, let me let me do the following. 392 00:48:59.460 --> 00:49:04.560 William Cheng: Okay, so I want to sort of draw on a set of slides over here. So let me 393 00:49:06.660 --> 00:49:08.100 William Cheng: Do this over here. 394 00:49:09.810 --> 00:49:11.700 William Cheng: Yeah, give me a couple of seconds to do this. 395 00:49:32.490 --> 00:49:38.790 William Cheng: Okay, so I'm gonna so let's say a horizontal axis over here is time, right. So let's say you have rate a lambda. Okay. 396 00:49:39.390 --> 00:49:44.520 William Cheng: So one over lambda is going to be the, the, you know, sort of the, the, the entire packet arrival time 397 00:49:45.180 --> 00:49:51.990 William Cheng: So some people was the thing that you know what it should do is that, you know, you should have one package arrived. Every one over lambda 398 00:49:52.320 --> 00:49:59.610 William Cheng: Right, so that will be sort of the typical way of thinking about it. Okay, before our warm up assignment. It doesn't mean that. Okay, so what it means is that 399 00:50:00.330 --> 00:50:03.720 William Cheng: You know, so that's a huge, you know, so, so this is this is the wrong picture. 400 00:50:04.260 --> 00:50:10.590 William Cheng: So we need to do is that you know when a packet arrive over here. If we know that the actual packet arrival time over here is equal to two, one 401 00:50:10.950 --> 00:50:17.880 William Cheng: Okay, then we say that the next package supposed to arrive. The next bag is supposed to arrive at t one plus one over lambda 402 00:50:18.780 --> 00:50:26.640 William Cheng: Okay. I mean, these two picture look exactly the same. Over here, as always for particular rabbit a tier one the next package supposed to arrive one overland up later. 403 00:50:27.240 --> 00:50:36.810 William Cheng: Okay, but the problem is that since we're doing a simulation, we're doing, you know, we're going to sleep and stuff like that. So the actual arrival time of this product that might be way out here. 404 00:50:37.860 --> 00:50:45.750 William Cheng: Okay, so that's it. This is packet number one and this packet number two the packet number two supposed to arrive at this time. As it turns out, he arrived, much, much later. 405 00:50:46.590 --> 00:50:54.570 William Cheng: Okay, so therefore we need to find out when is the packet actually arrived. Once we find out when the packet actually arrived, then we know that the next package supposed to arrive. 406 00:50:54.780 --> 00:51:02.550 William Cheng: One overlander later. So this is p to over here. So we say that the next package for P3 supposed to arrive at this time. 407 00:51:03.360 --> 00:51:11.880 William Cheng: Okay, but the actual arrival time over here, maybe, again, much, much later. Okay, so therefore you will see that in the end our timeline over here will be very, very different from the other timeline. 408 00:51:14.490 --> 00:51:14.790 Hardik Mahipal Surana: Okay. 409 00:51:15.450 --> 00:51:21.240 Hardik Mahipal Surana: And is there a possibility, where we expect the next party to arrive, but it never does. 410 00:51:23.340 --> 00:51:31.260 William Cheng: What it not supposed to happen right because the you know the worst case, you know, I guess it is possible if you're using a trace driven simulation. 411 00:51:31.650 --> 00:51:41.700 William Cheng: And then it will say that the NES tag is supposed to arrive, you know tomorrow because they interact arrival time is really, really big. Well, in that case, yeah. When you go to sleep. You'll see for very, very long time. 412 00:51:42.810 --> 00:51:56.850 William Cheng: Right. But you know if your program has no bugs, where you go to sleep, you know you're doing the simulation, right. So, so if you if you need to wait for 10 seconds, you need to call you know you sleep right USL EP 413 00:51:58.080 --> 00:52:07.350 William Cheng: 10 times 1 million, right. So that will be the number of number of microseconds that you need to sleep. Okay. So in a way, I mean you know if there's no bug in your code, you should always return 414 00:52:08.130 --> 00:52:23.970 Hardik Mahipal Surana: Okay, so. So ideally, the first third which is simulating the arrival of the packets. It needs to start with the first packet asleep for the time of one by lander wake up and then put in the next package and end up the same thing. 415 00:52:25.260 --> 00:52:32.490 William Cheng: Right, so, so, so that's, again, GA timeline over here. Right, so, so, so let's say this is time to go to zero I time to go to zero here. 416 00:52:32.910 --> 00:52:39.360 William Cheng: Okay, so what you will do is that you will go to sleep, or one over lambda, right. So one of the lambda over here, you expect to wake up over here. 417 00:52:39.600 --> 00:52:48.450 William Cheng: But in reality, you might wake up much, much later over here. So, so, at this time, will you wake up what you would do is that you're going to remember when you know when 418 00:52:48.900 --> 00:52:52.800 William Cheng: When you actually woke up over here because at this time you're going to generate the first packet 419 00:52:53.280 --> 00:52:58.290 William Cheng: Okay, so over here. I'm going to generate packet p one and we're going to add it to Q1 over here. 420 00:52:58.860 --> 00:53:08.310 William Cheng: Okay. And then when I finished. What I'm doing over here I have nothing to do. Now I need to to to to go to sleep, to make sure that when I wake up the next package supposed to arrive. 421 00:53:08.850 --> 00:53:16.260 William Cheng: Okay. So, therefore I'm going to take the current time. So by the time you know but but but by the time I'm ready to go to sleep. What time. What would I be what 422 00:53:16.710 --> 00:53:22.560 William Cheng: You know, if you look at a timeline. Right now it's here's the current time the current time of year CT obvious current time. Okay. 423 00:53:22.890 --> 00:53:30.180 William Cheng: The packet. He won't arrive at this time. And if you want overland over here, you're going to get that the packet P to supposed to arrive at this time. 424 00:53:30.990 --> 00:53:41.880 William Cheng: Okay, so what. So in this case, how much you just sleep well you should sleep this amount of time over here I because now you're you're you're already you have wasted some time. So now you need to sleep. This amount so that Peter is going to 425 00:53:42.660 --> 00:53:48.630 William Cheng: Peter was going to arrive at p one plus one or tier one over here key one plus one over lambda 426 00:53:51.360 --> 00:53:52.110 William Cheng: Does that make sense. 427 00:53:53.100 --> 00:53:57.750 Hardik Mahipal Surana: Yes. Could you please repeat the part of the CT. I didn't quite follow that. 428 00:53:58.230 --> 00:54:11.220 William Cheng: Yeah, so, so, so, so, so again, let's start from the beginning right at time you go to zero you try to go to sleep for one over lambda, as it turns out, you wake up much later you wake up at two one, so I time you go to one you create a packet 429 00:54:11.670 --> 00:54:19.710 William Cheng: OK. OK, so now I need to lock the new tax at the packet to, you know, to, to, to Q1 all this time the clock has continued to tick. 430 00:54:20.220 --> 00:54:30.270 William Cheng: Okay, so therefore the timeout opiates moving forward over here eventually when I'm doing what everything that I need to do you know I locked in new taxes at the packet. I'm locked in and tags and I compute. When is the next 431 00:54:30.690 --> 00:54:34.530 William Cheng: So when I finished all those calculation, the clock has moved to this time already. 432 00:54:34.950 --> 00:54:36.000 Hardik Mahipal Surana: Okay, okay. Go to do 433 00:54:36.150 --> 00:54:37.050 William Cheng: Okay, so therefore I 434 00:54:37.170 --> 00:54:38.430 Hardik Mahipal Surana: Don't for the fact that 435 00:54:39.540 --> 00:54:47.400 Hardik Mahipal Surana: The time taken to actually put the packet in queue. One is a part is should should be a part of one by lander. 436 00:54:49.230 --> 00:54:50.100 William Cheng: Yes. 437 00:54:50.190 --> 00:54:56.070 Hardik Mahipal Surana: Operations if some time has passed. We do need. We don't need to sleep again for one by land only for the remaining time should be sleeping. 438 00:54:56.130 --> 00:55:08.430 William Cheng: Exactly, yes, we need you to see for the remaining time right if it turns out that you know when you're ready to sleep, the current time is actually right here. What you pass the time it was supposed to arrive. So in that case, you should skip sleepy. 439 00:55:08.970 --> 00:55:20.340 Hardik Mahipal Surana: Ok ok and the use case where we started time zero. If we want to sleep for one by lambda, but we wake up at a later time. Does that happen because 440 00:55:20.610 --> 00:55:29.430 Hardik Mahipal Surana: When we want to wake up the thread isn't active like some other thread might be active in the current trend is in the queue is that the reason why it might wake up later than expected. 441 00:55:30.330 --> 00:55:38.040 William Cheng: Yeah, because so. So what happened is that, you know, you ask the operating system to say wake me up at this time. Right, okay. But nobody says that, hey, I'm busy. 442 00:55:38.910 --> 00:55:41.400 William Cheng: Right, because you your machine hosting another trick. 443 00:55:42.090 --> 00:55:44.760 William Cheng: Yeah, because your machine is running 50 different processes. 444 00:55:45.120 --> 00:55:55.590 William Cheng: Okay, so, and also you have our inner robs you of all kinds of going on you know machine. So, so even though the operating system tried to wake up at this time. In reality, you will wake up you know at a later time. 445 00:55:56.070 --> 00:56:03.600 William Cheng: Okay. Okay, so, so the operating system that we have like Linux and you know Unix and Linux opposites them, they are you know they are 446 00:56:04.140 --> 00:56:11.850 William Cheng: You can sort of call them the best effort operating system. So when you try to ask them to do something, they will try their best. They don't make any guarantees. 447 00:56:12.480 --> 00:56:22.140 William Cheng: Okay, they are operating system out there. There are called real time operating system for those opportunities and when you try to wake up at a certain time, the organism actually promise you. What's the worst case performance. 448 00:56:23.010 --> 00:56:35.640 William Cheng: Okay, a Linux doesn't have that I see. Okay. So, therefore, if you as albinism, say, Hey, wake me up at this time. It could be three seconds later you got woken up at the offices and say, Hey, I'm just trying my best. Okay. And that's perfectly okay 449 00:56:36.510 --> 00:56:45.060 William Cheng: Okay. Okay. So that's one thing you know sort of special about warm up to over here is that we need to understand that is the behavior of the operating system. And that's acceptable. 450 00:56:46.110 --> 00:56:47.520 William Cheng: Okay, yeah. 451 00:56:48.840 --> 00:56:56.250 Hardik Mahipal Surana: And you also mentioned earlier that we should be putting all of the data structures that we are planning to use within one new text right whether it 452 00:56:56.250 --> 00:56:56.580 William Cheng: Yes. 453 00:56:56.670 --> 00:57:05.760 Hardik Mahipal Surana: Thank you to all the bucket filter. So in that case, we would always ensure that only one of them even though. Like, for example, 454 00:57:06.300 --> 00:57:17.850 Hardik Mahipal Surana: The side which is working on arrival of the packets and the another thread which is working on on arrival of the tokens, although they work on two different pieces of data to different areas in memory. 455 00:57:18.540 --> 00:57:27.390 Hardik Mahipal Surana: We still want to put them in the same your text. So technically, when a packet is arriving, you cannot add a token. Is that right, well, 456 00:57:27.420 --> 00:57:33.600 William Cheng: So, so the reason we're doing that is that because they're sharing some data structure, right. So, so if you go back to 457 00:57:33.900 --> 00:57:40.050 William Cheng: The, the picture over here. There's Q1 right here's q one over here. There's Q2. Right. Okay. And then there's a token bucket. 458 00:57:40.740 --> 00:57:47.160 William Cheng: So what happened is that the packet of the packet arrival threat can actually move a packet from here, from q1 q2. 459 00:57:47.910 --> 00:57:55.560 William Cheng: Okay, the token deposit things that can also do the same thing. They can move a packet on Q1, or Q2. Well, so in that case you want to make sure that they don't interfere with each other. 460 00:57:56.700 --> 00:57:57.450 Hardik Mahipal Surana: OK. OK. 461 00:57:57.630 --> 00:58:02.400 William Cheng: OK. So, therefore, if you use notable mute hacks, then it's going to be a little dicey. 462 00:58:04.020 --> 00:58:10.290 William Cheng: Okay, so it's better to put everything over here instead of civilization box. So therefore, in this case, you're not going to end up with a programming bad 463 00:58:11.850 --> 00:58:12.150 William Cheng: Okay. 464 00:58:12.240 --> 00:58:21.630 William Cheng: So okay, so even though most of the time they work on different parts. But when they need to share the same data. Well then you got to have a way to to do to make sure that that works. 465 00:58:22.920 --> 00:58:34.290 Hardik Mahipal Surana: OK, so both the packet arrival. Third, and the token, or I will read both of them can do the task of checking the head of the Q removing the tokens and pushing it to Q2. 466 00:58:34.740 --> 00:58:37.410 William Cheng: Yeah. So once you have the new tax law. You can do anything you want. Right. 467 00:58:38.220 --> 00:58:53.250 William Cheng: Okay, so you should read the spec. The spec says when the the packet arrival. So I wouldn't try to put a packet into Q1, it needs to see if he was empty or not. Okay. If Q1 is empty already, then the package that you put into Q1, that will be the packet that will be at the head of the QR 468 00:58:53.850 --> 00:58:57.240 William Cheng: Okay. So, therefore, if there's enough token. Well, then you need to move into q two. 469 00:58:58.290 --> 00:58:58.560 Hardik Mahipal Surana: Okay. 470 00:58:58.920 --> 00:59:05.490 William Cheng: Okay. And also, I just want to emphasize that if they're a pack is already like you want. Well, then in that case, you don't really care. You just add the packet idea. 471 00:59:06.720 --> 00:59:23.340 Hardik Mahipal Surana: Okay. Okay, so the tread that works on arrival of the packets has the responsibility of checking Q1 and then moving it to Q2, does it also have the responsibility to trigger the removal of the tokens from the token bucket filter. 472 00:59:23.760 --> 00:59:29.370 William Cheng: Yeah, anytime you want to move a packet from q1 q2. You have to reduce the number of tokens in a token bucket. 473 00:59:30.360 --> 00:59:44.100 William Cheng: Right, because this you know this packet in order for it to go from Q1, or Q2 in need certain number of tokens. So if there's not enough tokens in the token bucket. You have to wait if there is enough. You need to remove the right number of tokens and then before you move into Q 474 00:59:44.310 --> 00:59:58.770 Hardik Mahipal Surana: Got it. OK. OK. So the, just to be clear, the thread that works on the arrival of the tokens in the token bucket filter its responsibilities, just to keep adding tokens to the filter and if it is over overflowing to just drop those tokens. Correct. 475 01:00:00.030 --> 01:00:08.940 William Cheng: partially correct, right. So, so the token deposit inside over here. What do you do today. We're at token right go from 012 or something like that. If there's too many. It will drop it. 476 01:00:09.240 --> 01:00:16.470 William Cheng: Okay, but what it will do is that every time when the increment a number of tokens over here, it needs to see if it can move the first packet from Q1, or Q2. 477 01:00:16.920 --> 01:00:17.670 Hardik Mahipal Surana: Okay, okay. 478 01:00:17.730 --> 01:00:18.330 William Cheng: Okay, because 479 01:00:18.660 --> 01:00:24.750 William Cheng: Because the only reason that there is a packet in Q1 is because that packet doesn't have enough tokens. 480 01:00:25.770 --> 01:00:38.910 William Cheng: Right. So, therefore, when you add a token into the token bucket this packet over here might have enough tokens out so you have to check it, if there's enough token, you need to really need to move on from q1 q2. You also need to remove the right number of tokens. 481 01:00:39.300 --> 01:00:43.110 Hardik Mahipal Surana: I see. Okay, okay, okay. Now, now it becomes clear. So the packet arrival 482 01:00:43.680 --> 01:00:52.020 Hardik Mahipal Surana: Ted will move a packet from q1 q2 only if the Q1 is already empty and there are enough tokens. 483 01:00:53.130 --> 01:00:53.550 William Cheng: Yes. 484 01:00:54.660 --> 01:00:59.970 William Cheng: Only if que en was empty, and now you are one packet into the packet will go to the head of the queue. 485 01:01:00.180 --> 01:01:03.630 William Cheng: And now if this packet has enough token, then he will move to you too. 486 01:01:04.830 --> 01:01:05.100 William Cheng: Okay. 487 01:01:05.160 --> 01:01:18.900 Hardik Mahipal Surana: Got it. Yeah. Yeah, that makes sense because I was thinking that you know the packet herbal thread might just have to keep adding packets, the token arrival time. I just have to keep adding threads and we might need a different side which manages the propagation from q1 q2. 488 01:01:19.440 --> 01:01:23.640 William Cheng: Right so so warm up to it was designed to be a little more complicated than that. 489 01:01:24.420 --> 01:01:25.290 Hardik Mahipal Surana: Okay. Okay, so 490 01:01:25.860 --> 01:01:31.050 William Cheng: This way, this way you write the packet arrivals threat and the token deposits, where they are working with each other. 491 01:01:31.470 --> 01:01:32.070 Hardik Mahipal Surana: Correct, correct. 492 01:01:33.720 --> 01:01:34.350 William Cheng: Okay, so 493 01:01:34.890 --> 01:01:47.730 Hardik Mahipal Surana: Not from a perspective of us doing this assignment. But another design of this token bucket filter could be that we could have a separate thread which just does the propagation of packets on q1 q2 and then removal of the tokens. 494 01:01:50.160 --> 01:01:51.600 Hardik Mahipal Surana: Like a possible design that could help. 495 01:01:52.680 --> 01:02:03.150 William Cheng: Yeah, that will. So if you have another thread over here, right, so that's that that's where it needs to be sleeping somewhere and then Robin said whenever you add 496 01:02:03.690 --> 01:02:20.220 William Cheng: You know, when whenever you add a packet into it. You want to wake up that thread. Um, I, I mean, maybe there's a way to get it to work again. But, you know, whatever the words that this thread is doing. They are, they can already be done by the packets and the or the token thread. 497 01:02:21.360 --> 01:02:38.220 William Cheng: So we can i don't know maybe it's an interesting exercise to sort of figure out, you know, you know, having more threads. Is it going to help or not. Okay. I think it will not help. Okay. Actually having, you know, just, you know, just the package where the tokens that that should be enough. 498 01:02:38.400 --> 01:02:43.170 Hardik Mahipal Surana: It should be enough, because I think if we add a new thought it might keep doing Busy waiting on Q1. 499 01:02:43.500 --> 01:02:47.700 William Cheng: Also, again you know that when you try to wait for something you have to go to sleep right so 500 01:02:48.150 --> 01:02:55.530 William Cheng: So in this class. We're going to learn, you know how to do it correctly. So what you have another threat. That's why is not allowed to do Busy waiting 501 01:02:56.430 --> 01:03:03.330 William Cheng: Okay, okay. So you just use an easy to sort of figure out how does it not too busy waiting and also wake up at the right time and get a little tricky. 502 01:03:03.840 --> 01:03:05.190 William Cheng: Regard yeah 503 01:03:05.490 --> 01:03:06.090 Hardik Mahipal Surana: Thank you so much. 504 01:03:06.150 --> 01:03:13.680 William Cheng: Yeah, so, so, by the way, just mentioned that in the spec. It also said something like, you know when something supposed to happen. It needs to happen as soon as possible. 505 01:03:14.430 --> 01:03:26.580 William Cheng: Okay, so if you wait for too long for something to happen. Well, then it's a bug in your code. Okay, so we add an extra thread over here, you got to make sure that that's where that you're gonna end up wasting extra time in that VIP because in that case it will be a buggy code. 506 01:03:28.200 --> 01:03:28.410 William Cheng: Yeah. 507 01:03:28.770 --> 01:03:29.370 Hardik Mahipal Surana: Thank you so much. 508 01:03:29.700 --> 01:03:30.300 William Cheng: Okay. You're welcome. 509 01:03:31.560 --> 01:03:37.920 William Cheng: Yeah, but we just want to add it. This is a sort of a good question because you know lots of people is going to get confused by this 510 01:03:38.160 --> 01:03:49.770 William Cheng: And they don't ask questions. So in the end, they're going to end up doing something wrong. Okay, so it's very important to understand, how's the the token, the packet arrival threat interact with the token, the positive throughout this way. 511 01:04:00.930 --> 01:04:02.970 William Cheng: Anybody else has a question. 512 01:04:19.680 --> 01:04:28.920 William Cheng: Okay, so if there's no more question. I'm gonna, I'm going to close the live lecture you know today and I will get this posted. So if you think of any other question. 513 01:04:29.610 --> 01:04:37.980 William Cheng: Feel free to come to the office or in the afternoon or, you know, send me email pose a question to your to the classical group. Okay. All right.