WEBVTT 1 00:00:02.159 --> 00:00:15.570 William Cheng: Welcome to electric 10 so now we're in Colonel one. So, current one is due on Tuesday, June 30 if you have co from previous semester, please don't look like a don't copy them best to get rid of it. 2 00:00:16.230 --> 00:00:22.440 William Cheng: You're supposed to be reading, you know, current FAQ, and you're supposed to be studying, you know, kind of someone with GDP right away. 3 00:00:23.190 --> 00:00:29.280 William Cheng: So if you don't know how do you GDP, you have to learn as soon as possible. Right. You know, I think that the colonel is impossible. 4 00:00:29.850 --> 00:00:36.300 William Cheng: To debug. If you don't know how to use GDP and the goal of today's lecture is that with this lecture is finish. 5 00:00:36.600 --> 00:00:42.000 William Cheng: You should have everything that you need to finish Colonel one because even though you don't have, you know, you don't know exactly how to do yet. 6 00:00:42.540 --> 00:00:47.130 William Cheng: But he sort of, you know, you, you're going to start doing this slowly and then hopefully at some point. 7 00:00:47.760 --> 00:00:55.440 William Cheng: You'll be able to finish the entire assignment. Okay, so the Colonel's. I mean, it's pretty difficult especially conceptually, they're kind of difficult. Yeah. 8 00:00:56.220 --> 00:01:02.970 William Cheng: Alright, so for Colonel assignment, the grading guidelines, the owner will gracious, as usual, the colonel waiting on is very different from warm ups. 9 00:01:03.330 --> 00:01:11.760 William Cheng: So this Friday and the discussion session. I'm going to sort of explain to you some of the sort of a new you know grading items in the colonel wedding guideline. 10 00:01:12.420 --> 00:01:17.370 William Cheng: So make sure that you read the carefully and if you're confused. If you're not sure, send me email. 11 00:01:17.880 --> 00:01:26.160 William Cheng: And you know the way to Ghana has a lot of stuff in there. So you should try to get as much as many partial credit points as you have. So you have to try all of those steps there. 12 00:01:27.060 --> 00:01:34.200 William Cheng: And please understand that, you know, we must use the same grading procedure for everyone. Right. If you want us to create it in a different way. We have to refuse. Yeah. 13 00:01:35.850 --> 00:01:44.490 William Cheng: All right. The Colonel one a gradient, the timeline is as follows. So today is Thursday. So, uh, till Thursday next week. 14 00:01:45.240 --> 00:01:50.940 William Cheng: You should keep things simple, keeping a driver you go to zero. Once you said driver equal to zero, you're going to start getting interrupts 15 00:01:51.270 --> 00:02:01.770 William Cheng: Okay, so it's much easier to do your kernel without interruption. So I will recommend to keep driving go to zero until you until you at some point you have to sit. Dr. We go to one now. 16 00:02:02.430 --> 00:02:09.570 William Cheng: So the first thing you need to do is that you need to get the internet process to start and quit. Okay. So in this case, all that's involved is that, you know, 17 00:02:10.800 --> 00:02:17.070 William Cheng: So, so your career is going to start in a function called bootstrap inside bootstrap. You're going to create process zero in a funny way. 18 00:02:17.520 --> 00:02:22.650 William Cheng: There and then you're given the first procedure of process zero. So, therefore, you don't have to write any code. 19 00:02:23.100 --> 00:02:31.770 William Cheng: You know, for the first procedure is implemented for you already. If you read a call. Very, very carefully, you will see that it will try to create process one and process. One is the entire process. 20 00:02:32.220 --> 00:02:41.280 William Cheng: Okay, so, so once you create process one process one has nothing to do and it will call it has nothing to do, it would just self terminate. 21 00:02:42.120 --> 00:02:49.590 William Cheng: Okay, so don't do anything and process one all just let itself terminate when itself terminate issue wake up process zero and zero is going to turn off the machine. 22 00:02:50.610 --> 00:02:57.900 William Cheng: OK, so again so happen is that, you know, you know, the first procedure of all these, uh, you know, all these all these processes. 23 00:02:58.320 --> 00:03:03.510 William Cheng: They will make function call and these function calls are not yet implemented and your job is to finish implementing all of them. 24 00:03:03.930 --> 00:03:09.480 William Cheng: So this particular process just has this pretty there's a procedure will work perfectly ok so again. 25 00:03:10.050 --> 00:03:18.840 William Cheng: You need to start President 00 and start process one process well with self terminated will wake up process zero and process zero what turn off the machine that will be the first step right 26 00:03:19.110 --> 00:03:30.030 William Cheng: After you get that to work, and you make sure that you Colonel halts cleanly gay then in process one the only thing that you have to do is to test the Colonel. So what you would do that you will call favor through a test. 27 00:03:30.570 --> 00:03:35.040 William Cheng: You know, from the first procedure or process. One of the functions caught in in progress. 28 00:03:35.850 --> 00:03:47.160 William Cheng: So was so favorites that has has lots of testing that I suggest you to test a little bit at a time. So you need to set see us for two tests equal to one. So remember, every time when you make any changes in incomplete. I am K 29 00:03:47.340 --> 00:03:53.430 William Cheng: You ever do make clean and then and then and then do a make right you have to wipe out the entire career or the colonel binary and then re compile 30 00:03:53.670 --> 00:04:03.390 William Cheng: Okay so started with CFO to test equal to one. So this way you only test one set of tests inside favorites right so if you pass everything you know then then again the 31 00:04:03.990 --> 00:04:10.230 William Cheng: quarter, quarter house cleaning. You said it to chew you said at the three and da, da, da. And I keep doing this until we get to eight. 32 00:04:10.740 --> 00:04:23.370 William Cheng: Okay, once it gets the A, then they are the one more set of tasks that you won't be able to pass until you turn driver equal to one. Okay. So, therefore, you know, and at that point. So, so after this year. Also, so you know it's going to be, you know, 33 00:04:24.960 --> 00:04:32.580 William Cheng: Maybe before next Thursday or after next Thursday. It doesn't really matter. So afterwards you need to set driving equal to one, incomplete. I am can again re compile everything 34 00:04:33.120 --> 00:04:40.890 William Cheng: So now is that any proc run, you have to run the colonel show kindness is very, very simple. You just copy a few lines of code, put it in, say you're 35 00:04:41.250 --> 00:04:50.040 William Cheng: The first procedure or you're in a process as you work when it works, it will print the three commands that are available to you. Help ECHO and exit when you exit it will kill 36 00:04:50.850 --> 00:04:56.490 William Cheng: You have exit is supposed to kill the process. The process will wake up the IPO process at idle possible turn off machine. 37 00:04:56.970 --> 00:05:02.100 William Cheng: That alright so at this point. If everything works so far. Would you do that you F3 K shell command. 38 00:05:02.460 --> 00:05:09.750 William Cheng: You need three of them, because in the grading guidelines the grading, it says the greater is going to run these three tests. Right. So if we need to create one commands for each one of these tests. 39 00:05:09.990 --> 00:05:16.260 William Cheng: Okay. Every canal, would you have to do that, you need to create a child process inside a child process you're going to run the specified function. 40 00:05:17.460 --> 00:05:26.850 William Cheng: Okay, so when you do something like that usually says he has for to test all the way to 10 and then you should be able to then what you want to do is you want to make sure that you, you can actually pass all the tests. 41 00:05:28.350 --> 00:05:33.000 William Cheng: OK. So again, when you get that far, you know, and if you confuse me show you said this me 42 00:05:33.450 --> 00:05:40.740 William Cheng: And also, you got to pay attention to the grading guidelines, it has requirement for Readme file and also to have a requirement for the kernel source code that you're supposed to submit 43 00:05:41.190 --> 00:05:50.760 William Cheng: So again, you need to satisfy all the requirement and don't lose any sort of simple points. Okay, some of the simple part over here can be easily satisfied if you just follow the instructions on that. 44 00:05:51.540 --> 00:05:56.340 William Cheng: Alright. So again, it's very, very important for you to understand every line of code in favor of that test. 45 00:05:57.480 --> 00:06:02.280 William Cheng: So last time we finished the first part of chapter four. We talked, we talked about the process. 46 00:06:02.580 --> 00:06:10.470 William Cheng: You know the process life cycles and the three life cycle and those, those are very related as we have all you have to implement your current one assignment that 47 00:06:10.890 --> 00:06:19.080 William Cheng: So now we're going to skip past the rest of Chapter four, and we're going to jump into we're going to talk about chapter five and Chapter five is about implementing threats. 48 00:06:19.590 --> 00:06:24.270 William Cheng: Okay, so therefore that's that start talking about it. So, so finally, we're going to get to sort of the meat of this 49 00:06:25.170 --> 00:06:34.440 William Cheng: That the other this class, talking about how to do all these implementation inside a carnal guys are chapter fries called processor management so want to sort of focus on processes and threats. 50 00:06:35.310 --> 00:06:38.610 William Cheng: So the first time we feel we're going to see is this the three implementation. 51 00:06:39.360 --> 00:06:46.350 William Cheng: Right. So, SO WITHOUT GOING TO GO GOING FIRST into the implementation one sort of talk about the high level strategy of how to implement that. 52 00:06:46.530 --> 00:06:54.840 William Cheng: So what are the high level strategy right I mentioned before, there are basically two different approaches. One is to implement fledging the Colonel. The other ones to implement the threats and the user space. 53 00:06:55.230 --> 00:07:02.010 William Cheng: Okay, so that's sort of the basic strategy. Where do you want to implement threats. He said, a kernel or is that a user space program. Yeah. 54 00:07:03.180 --> 00:07:11.580 William Cheng: So so so you implement threatened in the in the user space program. So in that case, you are implemented the piece or a library as a user threat library. 55 00:07:11.940 --> 00:07:22.710 William Cheng: Okay, if you're implementing the inside, Colonel. That means that the piece or a library is going to make system call and then or whatever it is you're coming out of Colonel and when you get inserted, Colonel. The Colonel is going to implement all these slides. 56 00:07:23.310 --> 00:07:31.800 William Cheng: Okay, so that's the major distinction, whether pizza libraries completing the user space or they're just going to make system call and then do all the 30 implementation insider carnal. Yeah. 57 00:07:32.640 --> 00:07:41.760 William Cheng: So, so we're going to look at several different approaches. One is known as the one by one model, guys. And this guy's. This is the case where the threats are implementing 58 00:07:43.110 --> 00:07:46.560 William Cheng: Implementing the colonel so Linux is like that. The windows like that. 59 00:07:47.370 --> 00:07:57.900 William Cheng: That and then we'll take a look at something called a two level model. And one of the, one of them is called the n by one model. The other one is called the n by n model. So in this case, the threads are implemented in user space library. 60 00:07:58.710 --> 00:08:05.640 William Cheng: Okay, and then going to sort of look at another sort of implementation of a two level model, known as the scheduler activation model. So we're gonna 61 00:08:06.180 --> 00:08:13.530 William Cheng: We're gonna sort of skip that for now because today I have to finish everything that you need to you to your current one. So I'm going to talk about the schedule activation 62 00:08:13.920 --> 00:08:23.220 William Cheng: Amato in the middle of the next second and in the middle of the next next lecture there, right. So let's take a look at these two approaches. The first one is the one by one model. 63 00:08:24.150 --> 00:08:34.470 William Cheng: Okay, so in this case over here, we can see that the Colonel, you know, so the one by one. Although the search I implement. Is that a colonel right so that's why I draw the picture like this, you know, all these threats are implementing sidecar know. So what about user threat. 64 00:08:35.700 --> 00:08:44.940 William Cheng: That. So the users. So the way that usually works over here is that we're going to study about your fast Colonel threat. And then what do we do is it'll go into the user space, almost like making the call. 65 00:08:46.860 --> 00:08:51.930 William Cheng: Okay, so, so, so, so the way you should think about is that when you create a process your process has a threat. 66 00:08:52.110 --> 00:08:59.790 William Cheng: That's that is running the user space right so often, it's not what you need to create another. So what do you do you call piece or create MP3 create it's a system call 67 00:09:00.540 --> 00:09:10.920 William Cheng: Okay, so therefore that's that come inside the colonel colonel. What do you do as a new career another threat and now both level returning to the user space and I have to study in user space and they're not here anymore. 68 00:09:11.490 --> 00:09:20.670 William Cheng: Okay. And then if you create another say you're gonna come into that occurred over here, create another set, and then this was on returning to the user space. So it's kind of, it's kind of backwards as what we were talking about chapter to 69 00:09:21.480 --> 00:09:24.840 William Cheng: Chapter two, is that, you know, we create a threat, you create them in the user space. 70 00:09:25.470 --> 00:09:32.250 William Cheng: Okay, but since we're using a one by one model you can only create a threat in the kernel because there's no way to do that the user space. 71 00:09:33.000 --> 00:09:41.160 William Cheng: Okay. So, therefore, you know, a piece or create is going to be a system call you come inside the cardinal you create a kernel and then you return back into the user space, then 72 00:09:42.120 --> 00:09:52.200 William Cheng: So conceptually is very simple. Right. You know, every first starting out a kernel. They go return into the user space do something and eventually when you copy for exit you die inside the carnal. Yeah. 73 00:09:53.610 --> 00:10:05.850 William Cheng: Alright, so, so this is sort of the simplest and most direct approach as to use this one level models and this case, etc. Implementing the user space, which means that you know all the P3 library called we here they are implementing as a system called 74 00:10:06.570 --> 00:10:15.090 William Cheng: Okay, so. So for example, when you call piece of create. Well, I just didn't call you come into the kernel and we create thread inside the kernel. And why do we have to do that what because I sweat, you know, 75 00:10:15.480 --> 00:10:22.980 William Cheng: You know, because there's an implement inside of Colonel, so therefore you can only create search inside the colonel right when you call piece of a joint. Oh, why don't you copy. So I joined 76 00:10:23.520 --> 00:10:30.150 William Cheng: What if you want to join with another three you want to wait for another threat to die while since I implement inside the cardinal so again you have coming out of Colonel 77 00:10:30.420 --> 00:10:33.480 William Cheng: Right in the user space. There's no way for you to wait for another set to die. 78 00:10:34.140 --> 00:10:40.950 William Cheng: Okay, so therefore pizza joint also need to come. Is that a carnal okay piece of exit, as it has to be a system called you coming out of kernel. And now you can 79 00:10:41.610 --> 00:10:55.830 William Cheng: Now your second self terminate inside the colonel because you're setting because you're a thread cannot self terminate in the user space. Okay, so all these songs over here. They're all you know they're they're all system call. Now what about function like piece of new tax law. 80 00:10:57.780 --> 00:11:04.140 William Cheng: Okay, that this piece right so we were asked the question that you know there's peace to a new tax law has to be done inside the Colonel. 81 00:11:04.710 --> 00:11:07.500 William Cheng: what the answer is. The answer is it depends. 82 00:11:07.800 --> 00:11:16.710 William Cheng: Right, so, so if I were to implement that Colonel, that means that if you have a threat. You want to interact with another swear you have to interact with them inside the cardinal because threats are implementing sort of Colonel 83 00:11:17.100 --> 00:11:21.360 William Cheng: Okay. Will you call piece of a new time slot. If the music is not available. 84 00:11:22.170 --> 00:11:29.400 William Cheng: Okay, if the music is not available. What do you have to do. Well, you have to come to you have to go to sleep. Inside the colonel waiting for the military attacks to be unlocked. Right. So in this case, 85 00:11:29.640 --> 00:11:38.490 William Cheng: If you have to go to sleep, you have to go to sleep inside of current also, therefore, in this case piece of admin type side at some point is going to become a system call you will come inside the cardinal when the thread goes to sleep. 86 00:11:39.150 --> 00:11:40.770 William Cheng: Okay. What if the music's is available. 87 00:11:41.310 --> 00:11:52.050 William Cheng: If the text is available, then you don't really need to come to the inside a cut off because nobody else around me attacks. So in this case you do not have to interact with any other threads. So it is possible for peace and mute hugs to 88 00:11:52.320 --> 00:11:54.630 William Cheng: You know, to, to return right away without coming out of Colonel 89 00:11:56.280 --> 00:12:07.920 William Cheng: Okay, so therefore, again, some of the system, you know, some of the pieces are because of your has to be a system call and some of them doesn't have to be a system running and that should be completely implemented in the user space. Right, right. So, 90 00:12:09.900 --> 00:12:16.740 William Cheng: So the problem with the you know the the one, the one by one model is that you've every piece or a library function. They're all implementing the system call 91 00:12:17.070 --> 00:12:26.160 William Cheng: System called we saw before. It's going to be slow, right, because when you call we make a system call you're gonna, you know, sort of trapping to the Colonel, you're going to go to the horror abstraction layer, you can execute a lot of the code. 92 00:12:26.490 --> 00:12:33.870 William Cheng: And eventually going to do something. So the kernel and then it will you return, you're gonna get execute a lot of code. Okay so system called are actually very expensive. 93 00:12:34.530 --> 00:12:38.820 William Cheng: Okay, so if you can stay inside a user space, that would be great because he will be running as fast as you could. 94 00:12:39.030 --> 00:12:46.530 William Cheng: Every how we make the system call while sometimes you something you don't have a choice. If you need to access a hardware device, you cannot do that, you have to ask operating system point out 95 00:12:46.680 --> 00:12:58.020 William Cheng: So under know cases those cases, you know, you don't really have any choice. Okay. When you have a choice. You want to do things in the user space. Okay. Over here, it says if you don't have to make a system called your code is going to run 20 times faster. 96 00:12:59.130 --> 00:13:06.720 William Cheng: Okay, so therefore that's another that that's a very, very good good good good reason to stay in the user space. Yeah. So now, if you think about your warm up to par to to to program. 97 00:13:07.500 --> 00:13:11.850 William Cheng: You know if you know Peter I create is a system call, is that going to steal anything now. 98 00:13:12.810 --> 00:13:20.700 William Cheng: Well, the answer will be no right because you called Peter Korea four times or five times. And once you're done, you can run your program for a very long time. So even if piece that creates a little slow 99 00:13:20.910 --> 00:13:28.710 William Cheng: It doesn't really matter. What about pizza joint you only joined four times or five times. Again, you know, it doesn't really impact your performance. But what about pizza mutates lock. 100 00:13:29.850 --> 00:13:33.510 William Cheng: I mean, you know, your warm up to his calling piece of meat. Is it better. How many, you know, 101 00:13:34.560 --> 00:13:40.560 William Cheng: How many packets you assimilate indicate, you can go from, you know, a few hundred times a to a few thousand times to a few million times. 102 00:13:41.160 --> 00:13:46.950 William Cheng: Okay. So, therefore, if every piece or a new title is going to be plenty times slower. Well, then in that case you will not, you will be running 103 00:13:47.520 --> 00:13:59.010 William Cheng: We're running very slow. Okay, so how do we actually make the the wonderful moto. Moto moto go faster. Right. So one thing that we have to do is that we have to make peace any tags lock as fast as possible. 104 00:13:59.580 --> 00:14:09.150 William Cheng: Okay, all the other you know all the other piece of the library call you know if they are a system called. This will not a big deal. Yeah. Alright. So, whoops, what did I go 105 00:14:11.160 --> 00:14:12.600 William Cheng: Okay, so, so 106 00:14:13.680 --> 00:14:14.820 William Cheng: What is today. 107 00:14:20.190 --> 00:14:26.190 William Cheng: Okay, so. So the basic idea over here is that, you know, for for piece of meat has like a, how do you actually make it 108 00:14:26.760 --> 00:14:34.260 William Cheng: Make it faster, right. So, so the key over here is that if the meat Ax is not available, you should grab the new tax without coming inside the Colonel. 109 00:14:35.100 --> 00:14:39.450 William Cheng: Okay, so, so, so, so if you think about your warm up to. Does that happen a lot 110 00:14:40.050 --> 00:14:49.020 William Cheng: Okay, think about all your search over here. Right here you have a package today you have the token. So you have the server side over here whenever they tried to lock the new tax is the mutates available or the meat is not available. 111 00:14:50.160 --> 00:15:00.240 William Cheng: Okay, if you think very, very carefully, you will you will realize that for your warm up to most of the time when you're still a copy stereotypes are the new tax is always available. Why is that 112 00:15:01.260 --> 00:15:08.310 William Cheng: Right, because you have all these four threads over here. They're all sleeping, you know, sort of asynchronously. So most of the time, all your fault that they're all sleeping. 113 00:15:08.760 --> 00:15:15.690 William Cheng: So anytime, or one of the third wakes up, chances are all the other threads are sleeping. So, this you know this guy when he tried to login you tax the tax is going to be available. 114 00:15:16.200 --> 00:15:23.340 William Cheng: Okay, so therefore you can sort of think about for application that looks like Walmart to piece or a new tax law because actually, you know, can be implementing the fast way. 115 00:15:24.270 --> 00:15:35.010 William Cheng: Okay, so therefore the solution, you know, to the one by one model is that you have to make sure that your tummy tucks is available. You grab it and user space without coming out of college. So this way you know you performance will be able, what will be acceptable. 116 00:15:36.240 --> 00:15:47.700 William Cheng: So we're gonna sort of see how this can be implemented. All right, so, so, so that's it for the one level model I mentioned before, you know, lineage, does that mean it's actually it does it in a strange way. So instead of, you know, 117 00:15:49.680 --> 00:15:52.440 William Cheng: So the way to implement multi threading is that you know what 118 00:15:53.340 --> 00:16:01.350 William Cheng: What will you try to, you know, a core piece of creative, they actually they make make a different system call. Okay, this isn't called me a call is no as a closed system call 119 00:16:01.680 --> 00:16:11.700 William Cheng: In the closest them call here. This actually works for a process and also for a threat because in Linux what they actually do is that they were they're implementing a single thread per process. 120 00:16:12.060 --> 00:16:17.460 William Cheng: Is almost like a colonel colonel summons a single separate process in Linux. They also have single separate process. 121 00:16:18.000 --> 00:16:28.680 William Cheng: Okay. So in this case, when you create a new thread you basically also have to create a new new process. If you are sharing the entire address space with the new threat. Well, in that case, these, these two processes are basically one process. 122 00:16:29.160 --> 00:16:36.690 William Cheng: Okay. Because if they're sharing the same outer space. Well, then in that case, they're the same process. So in this case, multiple processes acting is acting as multi threading. 123 00:16:38.070 --> 00:16:41.940 William Cheng: Okay. So as it turns out that you also will you try to make a fork system call. You can also make 124 00:16:42.630 --> 00:16:45.420 William Cheng: The instead of implementing the forces of apart from scratch. 125 00:16:45.600 --> 00:16:55.830 William Cheng: You can also use the code system call. So in this case, what you are trying to tell you. I'll bring this ism is that when I create a new process, right, because we're doing single separate process. This process will not share anything with a parent process. 126 00:16:56.310 --> 00:17:01.320 William Cheng: Okay, if you don't share anything. Why this guy's you will make a copy. Why know case, they will be the same thing as a fork system call 127 00:17:02.400 --> 00:17:09.450 William Cheng: Okay, so in Linux they implement one column system call and this closed system called share by the fourth system call and also by piece or create 128 00:17:09.690 --> 00:17:20.100 William Cheng: Okay. So typically what happens is that when you call it the fourth system call will try to clone. This isn't going to make copies of everything. And what does everything, everything's going to be your virtual memory which is your address space you're extending 129 00:17:21.630 --> 00:17:30.510 William Cheng: The data structure, instead of fosters that which is the file descriptor table. So in this case, you know, we're also going to make all these copies and also you know the the signal information. 130 00:17:31.020 --> 00:17:34.710 William Cheng: So in that case, if you don't want to share anything. What then basically you can run this a separate process. 131 00:17:34.980 --> 00:17:44.820 William Cheng: Then if it turns out that you call club because you're doing Peter create. Well, in that case, we're sharing everything. So even though we're running in multiple, multiple processes that are basically acting as a single process. 132 00:17:45.720 --> 00:17:53.880 William Cheng: Okay, so you're not really responsible for this. So Lynn is called as the variable way processes against the textbooks would also talk about. I also know 133 00:17:54.510 --> 00:17:59.910 William Cheng: A little more detail. So there's a lot of it is that we have multiple threads over here and now. 134 00:18:00.480 --> 00:18:10.020 William Cheng: What do you have, we have multiple processes sharing the address space, they're acting as one process. And now we call get process ID. If you try to if you try to get the process ID. 135 00:18:10.500 --> 00:18:18.480 William Cheng: Which process ID, should you get right because he ended up with several processes. So it's a little confusing. So insulin as they sort of have to sort of figure out 136 00:18:19.110 --> 00:18:26.490 William Cheng: A way to determine a unique process ID for a group of workflow group of processes, right, because they're all sharing the address face. Yeah. 137 00:18:26.940 --> 00:18:35.070 William Cheng: So they so all these, you know, all these processes for a threat group and a thread group has a leader. Anyways, we're not going to get into too much of these detail over here. We just want to sort of 138 00:18:35.430 --> 00:18:39.420 William Cheng: make you aware that where you have a single process, a single super process. 139 00:18:39.930 --> 00:18:48.870 William Cheng: You know, the application space we're going to end up with a little bit extra complication that all right Linux also implement what I mentioned before, for the piece at a time slot. 140 00:18:49.350 --> 00:18:53.160 William Cheng: Okay, so what it will do is it will check the new text available user space. If it's available. 141 00:18:53.520 --> 00:19:04.230 William Cheng: In the user space, it will not come inside the colonel so Linux actually called this new tax implementation, they call a few texts guys a few tax stands for fast user space new text. 142 00:19:04.650 --> 00:19:10.230 William Cheng: Okay, so it's fast because it is a meetings available, it will grab the new tax without coming inside the colonel well 143 00:19:10.680 --> 00:19:20.370 William Cheng: So, so they can use few times to implement all the function that we talked about before you text them up for can just grab all that kind of stuff. Yeah. So we're going to talk about that towards the end of today's lecture. Now, 144 00:19:22.620 --> 00:19:32.790 William Cheng: Alright, so that's the one level model again very, very simple. So the two level model over here. So in this case, you know, the threads are implemented in the user space because of the user state level. 145 00:19:33.060 --> 00:19:40.260 William Cheng: The user level library over here, played a major role. Okay, so when you copy. So I created pizza joint all the season and done in the user space there. 146 00:19:40.680 --> 00:19:47.550 William Cheng: There are two different version. One is that there's only a single kernel threat and this one is called the Empire one model where there's end user threat. 147 00:19:47.760 --> 00:19:53.730 William Cheng: And one kernel threat and the other one has the multiple kernels. So this one called the n by n model. So the idea here is that 148 00:19:53.910 --> 00:19:58.740 William Cheng: The number of users to enter number Colonel says they are different. Okay, so this is done for every user 149 00:19:58.920 --> 00:20:08.370 William Cheng: For every user process. Yeah. So let's take a look at the end by one model for us over here. So the picture look like this. We're going to have one set inside the kernel and then multiple threads in the user space. 150 00:20:08.880 --> 00:20:15.570 William Cheng: So in this case, when copies or create. It's a lot. It's a library is a C library call so therefore you create a thread in the library. You don't have to come inside of carnal. 151 00:20:15.930 --> 00:20:20.370 William Cheng: Okay, so when you have a company's out of Colonel well again when you have the companies that occurs when you make a system call 152 00:20:20.850 --> 00:20:28.860 William Cheng: OK, so the entire piece or a library. They're all in the user space. So, so in that case the piece where library is, you know, that doesn't involve any system call 153 00:20:30.270 --> 00:20:40.290 William Cheng: Okay. So in this case, you know, the only time you make a system called is like when you open a file where you do all the regular system calls in this case gonna come inside a carnal man. So, so this is one of the earliest way about implementing threats. 154 00:20:41.700 --> 00:20:52.560 William Cheng: Okay, so this is the battle days in the good old days, they don't have multi threading, so they will actually experimenting with multi threading. So, therefore, you know, as far as the operating system is concerned, there's no such thing as a kernel threat. 155 00:20:52.980 --> 00:21:00.870 William Cheng: Because they because they have no concept of threads so. So in this case, you know, if you are a process. You're just a process and your processes running in the user space. 156 00:21:01.860 --> 00:21:09.060 William Cheng: Okay, so in this case right so if you don't have threats as far as the colonel is concerned, your processes running either running the user space are running out of Colonel 157 00:21:09.330 --> 00:21:15.600 William Cheng: There. So if you're running the user space. And if you're experimenting with threads going to create a bunch of the colonel is actually not aware of that. 158 00:21:16.650 --> 00:21:23.040 William Cheng: Okay, so all the studying that you do is completely user space, so, so, so, so your process only coming out of Colonel when you make a system call 159 00:21:23.130 --> 00:21:33.360 William Cheng: So who makes this is a ball against the operating system doesn't care because the ordering system doesn't know about threads. So, any, any one of these threads when they make a system call and boom, your process is not going to be inside of kernel. And if your 160 00:21:34.020 --> 00:21:45.270 William Cheng: If your process over here. I'll try to talk to the disk controller. Okay, so I've been inside your thread over here, you know, the start over here, go talk to this controller and now your process is going to sleep in the iOS device. Q. 161 00:21:46.320 --> 00:21:56.520 William Cheng: Okay. So in this case, once this happened as far as the operating system is concerned, your processes city i o que your process will never get the CPU back until this to your process go back into the user space. 162 00:21:58.170 --> 00:22:00.630 William Cheng: Okay. So this case is kind of weird over here. So, for example, 163 00:22:00.900 --> 00:22:07.950 William Cheng: Since you're playing with multithreading one of the users to head over here is going to make a system called companies that are current all as soon as you do that as soon as you go through our phones. 164 00:22:08.160 --> 00:22:20.700 William Cheng: For fall asleep inside of Colonel no other user thread over your get the CPU back because as far as the operating system is concerned, your kernel prot you your process is sleeping. Is that a colonel. So therefore, there's no no reason to give back to do 165 00:22:22.050 --> 00:22:28.860 William Cheng: To give you better sees the CPU. Okay. So, therefore, all your other thread will never get the CPU, guys. He's not a problem. I mean, you know, 166 00:22:29.280 --> 00:22:32.550 William Cheng: Yeah, so, so, so it's not a serious problem because eventually you're going to 167 00:22:32.970 --> 00:22:43.800 William Cheng: The user is going to finish waiting for the iOS device and it's going to go back to the user space one. In that case, you know, all the other thread. So, so why should go back into the user space. And now you can do threat switching completes our user space. 168 00:22:45.120 --> 00:22:53.730 William Cheng: OK, so again this is done, long time ago, or when people experimenting with so people don't do this anymore because, you know, because this is this really a weird way of doing it multithreading 169 00:22:54.600 --> 00:23:04.530 William Cheng: Right, so, you know, so, so, so, so get everything can be done in the user space, guys. So this is actually, you know, so I guess for for some ecosystem. 170 00:23:05.100 --> 00:23:15.780 William Cheng: They were they, they did. I guess they do the through this workflow for for quite a, quite a while now. So the major advantage. What this one it's going to be fast, right, because there's no system called will you do multithreading 171 00:23:16.320 --> 00:23:20.940 William Cheng: pizza, pizza joint pizza music sounds better all user space operation. So therefore, 172 00:23:21.540 --> 00:23:33.720 William Cheng: Therefore, you know, this is the fastest way to implement because it right. The major drawback over here is I was one of the 30 the system call you coming out of Colonel then motor 13 is going to be stopped right because because you never get the CPU back 173 00:23:34.380 --> 00:23:45.270 William Cheng: Now alright so we're here. But yeah, well, by the way, you know, again, this is done when you're experimenting with multi threading and there's never any true multi threading, right, because you know the CPU only give you 174 00:23:45.570 --> 00:23:52.290 William Cheng: You know, the, the organism only give you one CPU. So even when you have multi threaded multi multiple threads over here. They're running concurrently. 175 00:23:52.560 --> 00:24:00.240 William Cheng: While you only get one CPU. So, therefore, you know, the other piece of our library has a scheduler decide which thread. We're running out of CPU because you only get one CPU. 176 00:24:01.140 --> 00:24:07.080 William Cheng: Okay, so, you know, well, you don't really have power to power them. So when you come into the kernel. And then, and then again you lose the palace and 177 00:24:07.440 --> 00:24:16.470 William Cheng: So you know it's it's really not a big deal. Although they will be nice, you know, if you're coming inside the current over here, you can actually get back the CPU and continue to run the other user threat. 178 00:24:17.340 --> 00:24:24.420 William Cheng: Right, because you know if you know if one of the companies that are currently waiting for iOS device. What, in that case, the IoT device, it's, it's 179 00:24:24.870 --> 00:24:32.550 William Cheng: It's a different piece of hardware. So, therefore, you should be able to get the CPU back and run another threat now. So in the good old days to actually try to try to get that to work. 180 00:24:33.300 --> 00:24:35.430 William Cheng: Well, they will come up with something like the following. 181 00:24:35.610 --> 00:24:45.630 William Cheng: So for example, when you make a racism call you know companies that are currently going to end up sleeping. So what we need to do is that we need to devise a way to give the CPU back, you know, to all the other user level three, so that they can run 182 00:24:46.200 --> 00:24:49.590 William Cheng: Okay, so what do you do, right. So, so every system call. Okay. 183 00:24:50.580 --> 00:24:59.610 William Cheng: Why not every system for some of the system called here. You can use this approach. Okay, so I'm gonna say in the regulatory system called over here. We want to make sure that the system called doesn't get blocked inside the Colonel. 184 00:25:00.390 --> 00:25:06.210 William Cheng: Okay, so what you will do is that you actually use another system called over here. The system was called will read. So this is some call 185 00:25:06.540 --> 00:25:18.030 William Cheng: So what this system does is that it's a non blocking system call whenever you make this function called over here you will always you always return from the colonel right away anyway user error number to indicate whether you start reading inside of kernel or not. 186 00:25:18.750 --> 00:25:27.990 William Cheng: Okay, because the, the other thing was read over here. Is that what you call read. You know what will he make a racism Pokemon Go inside a carnal. It is possible, the kernel has already data for you. So in this case you can return right away. 187 00:25:28.890 --> 00:25:38.280 William Cheng: Okay. So in this case, when you call will we if you return the number of bytes. That's referring to this buffer over here. That means that the data is already inside colonel and then kind of just return you to 188 00:25:38.760 --> 00:25:41.670 William Cheng: The data. So therefore, your risk free system can return right away. 189 00:25:42.540 --> 00:25:53.820 William Cheng: Okay, if it turns out of the colonel doesn't have the data why neck is the current on need to start and I operation and then get the data to get DNA into memory and then wake up your threat. So in this case, this function will return right away. 190 00:25:54.120 --> 00:26:02.940 William Cheng: With Eric or equal to minus one right and if you check if Aaron number over here. If the error number equals two. I don't if you can read this over here if it equals two, he would block. 191 00:26:03.750 --> 00:26:11.970 William Cheng: That, that means that if I continue from this point, I'm going to end up blocking. So the Colonel, right. So, therefore, what I should do is that I should make our user, throw it over here. Go to sleep. 192 00:26:12.750 --> 00:26:23.130 William Cheng: That. So again, if the air number of equally, it will let me say inside the Colonel, they started IO operation for you and it's going to take some time to finish, but in the meantime dysfunction return over here. So you're in user space. 193 00:26:23.880 --> 00:26:28.230 William Cheng: So in this case, my thread over here will call a sad way to wait on the seventh floor and now 194 00:26:28.470 --> 00:26:36.360 William Cheng: In some way over here. So, how to implement some way. Right. It's almost like new tax law over here. So this assembly over here. You're going to cause switch to give the CPU to another threat. 195 00:26:36.810 --> 00:26:45.450 William Cheng: Okay, so this way you know your thread is going to be end up sleeping on a semi for Q and then you can give a CPU data set. And now you can actually do multithreading 196 00:26:46.470 --> 00:26:57.000 William Cheng: There so they don't know what the Iraq wishes is finishing the Colonel. How does it, I should wake up your threat well. So in this case, what happened is that, you know, so, so, so in this case, you know, when the, when 197 00:26:58.320 --> 00:27:07.860 William Cheng: Let's say that this that this is transferring data for you when it finishes is going to interrupt the CPU instead of, you know, observers routine. What it will do is that he will actually make an appt call and then wake up your third right here. 198 00:27:08.460 --> 00:27:16.860 William Cheng: Okay, so this way you know this will say, oh, you know, my other data that I'm waiting for now has been a transfer. So therefore, therefore, he will return on the function 199 00:27:18.420 --> 00:27:28.890 William Cheng: Okay, so lots of the system called over here. They all have to implement it this way, and they have to implement a lot of non blocking system calls or this way, you know, they will all return you will block and then can actually go to sleep and all this kind of stuff. Okay. 200 00:27:29.370 --> 00:27:33.900 William Cheng: So, so, so, so, as it turns out, this is one of the solution that people actually come up with 201 00:27:34.680 --> 00:27:40.410 William Cheng: So for every, you know, open file residence guys you know songs, you're dealing with a file for every fall over here we're going to 202 00:27:40.800 --> 00:27:46.680 William Cheng: Set up a center for. So if you're waiting for a data to get transfer for file. Well, then, in this case, you know, full, you know, full, full, full 203 00:27:46.980 --> 00:27:51.930 William Cheng: Full full for every file. They got have associated 74 and they can actually go sleep on the seven folks you 204 00:27:52.800 --> 00:28:00.720 William Cheng: Know the major drawback with this approach is that this is not a general solution they only work with some IO objects. It doesn't really work with all the objects. 205 00:28:00.870 --> 00:28:07.080 William Cheng: OK, so again. Now, some of them that has a file descriptor like this and then they can actually they will start our operation and then they 206 00:28:07.290 --> 00:28:15.510 William Cheng: And then you can actually sort of wait for the operating independently, then this particular schema work. But as it turns out that there are things inside Colonel cannot be done this way. 207 00:28:15.930 --> 00:28:25.560 William Cheng: Okay, so again this is not a general purpose of solution. And in the end, sometimes when you're three I made a system called there's no way for you to return the CPU back to back to the user space. Yeah. 208 00:28:27.180 --> 00:28:38.070 William Cheng: So this is the one model. The next one over here is the number one and by a model. So they are em user thread over here and there. K. Colonel thread over here. So in this case of hobbies. I want one of the threads over here. 209 00:28:38.550 --> 00:28:46.080 William Cheng: You know, make a system called right want to make a system called we hear it turns into a colonel threat over here. And now you can actually see that we can actually support three more Colonel 210 00:28:46.680 --> 00:28:56.730 William Cheng: Three more users, right over here. So if we have a lot of CPU, we can actually give three CPUs to these user thread over here. So when everyone on that make a system called they going to have a colonel fed over here to support that. 211 00:28:57.780 --> 00:29:05.040 William Cheng: Okay, so, so, so this is the solution for the is this is this one a solution that taken by some of the UNIX system like the Solaris operating system. 212 00:29:05.430 --> 00:29:09.900 William Cheng: they implement the n by n model. So again, the advantages over here is that they are super fast. 213 00:29:10.470 --> 00:29:16.290 William Cheng: But this analogy over here. It's going to be the same problem as n by one model because what if, you know, so in this case. So let's say that 214 00:29:16.770 --> 00:29:20.400 William Cheng: This particular case you get four CPUs over here to the user threat over here. 215 00:29:20.580 --> 00:29:26.850 William Cheng: Okay. One of them is going to make a system called so now it's going to go inside. Go school co sleeping side of kernel and did the second one is going to make a system called 216 00:29:27.030 --> 00:29:38.070 William Cheng: The third one is going to make a system called and now we are in exactly the same configuration as the end by one model when the fourth one, make a system called now all the other thread in the user space will not be able to run concurrently. 217 00:29:39.420 --> 00:29:51.570 William Cheng: OK, so the text will actually talk about another case over here where you are using, you know, some data structure, instead of kernel, which we haven't really talked about that will actually cause some kind of a deadlock. Okay. So then, you know, the idea here is that, you know, the 218 00:29:52.830 --> 00:29:55.350 William Cheng: I guess you know over here that the dialogue eventually 219 00:29:56.610 --> 00:30:04.920 William Cheng: So anyways, we're not gonna talk about this case. Anyways, so. So the problem here is at the end by one and by a model eventually is going to turn into the inbox tomorrow have exactly the same problem. 220 00:30:05.550 --> 00:30:16.140 William Cheng: Okay. So what is the solution over here guy, the solution over here for suppliers. It's actually pretty simple solution is that, you know, when you use up all the colonel thread next time when you make so 221 00:30:17.370 --> 00:30:22.230 William Cheng: We use the last Colonel inside the Colonel, they will create another Colonel threat for you. 222 00:30:23.730 --> 00:30:27.540 William Cheng: Okay so anytime. Anytime you need a colonel threat. What do we do that is that is that will you start with you. 223 00:30:27.840 --> 00:30:36.480 William Cheng: When you start your process, you know, the Colonel. The Colonel will create a bunch of Colonel, so that's for you the example that we saw over here is for. If you need more the colonel actually create more stress for you. 224 00:30:37.110 --> 00:30:41.010 William Cheng: Okay, so this way you will never get into this, the situation of a deadlock inside 225 00:30:42.330 --> 00:30:49.200 William Cheng: Okay, so, so, so you know way, you know, in the end, if all the threads over here. They all make system Hall, you're going to end up with exactly the same as the one by one model. 226 00:30:49.590 --> 00:30:58.800 William Cheng: Okay, so again, the major difference over here is that all the functionality are implementing the user space. Okay. So, therefore, if you if you use n by n model. You still got to be much, much faster than the 227 00:31:00.030 --> 00:31:03.210 William Cheng: Than the one by one model there. But again, it's a little more complicated. 228 00:31:05.880 --> 00:31:12.930 William Cheng: So, so, the problem with a two level model over here. One is the IO blocking problem. The other problem is known as the priority inversion problem. 229 00:31:13.500 --> 00:31:22.140 William Cheng: The partying version problem, you know. So what is party version. Right. So, so if you go back to the picture over here because we have multiple user level throughout. We have the multiple kernels that over here. 230 00:31:22.650 --> 00:31:27.630 William Cheng: in Pisa library we try to create a piece that you can actually set the third party level right so I can say that 231 00:31:27.810 --> 00:31:41.610 William Cheng: This is part of the level 123456 okay so inside the Colonel. The Colonel stick and also can happen either party level. So while I mean is it inside the Colonel, the priority level is 1234 like there's just a reverse order. So when this 232 00:31:41.820 --> 00:31:51.720 William Cheng: Going inside Colonel is going to become a low party things are Colonel well at the same time. So, number six over here also make a system Hall and they'll say that it got picked up by by by this kernel thread over here. 233 00:31:52.200 --> 00:31:57.240 William Cheng: Okay, so in that case, when both of them simultaneously going into the kernel. Which one is going to return for us. 234 00:31:57.540 --> 00:32:01.920 William Cheng: What the one with a higher priority inside the kernel that one's going to return for. So this one is going to return for us. 235 00:32:02.100 --> 00:32:12.180 William Cheng: And now the application programmer is going to be very upset the application, as I say, hey, this one has party one, and this one has party six when they both simultaneous going out of Colonel, I expect this one to return first 236 00:32:13.380 --> 00:32:16.860 William Cheng: Okay, so therefore, in this case, you know, this is known as the priority inversion problem. 237 00:32:17.550 --> 00:32:19.920 William Cheng: And as it turns out, this one is a pretty nasty problem. 238 00:32:20.310 --> 00:32:28.260 William Cheng: Because why because that will you try to solve one of the party and version problem by come in with some clever solution as soon as you solve that problem. There's gonna be another party version Poppins gonna pop up. 239 00:32:28.830 --> 00:32:35.820 William Cheng: So so so even though these problem are really, really. Oh, even today, when you look at the opposite of conferences, they are still solving party version problem. 240 00:32:36.510 --> 00:32:47.790 William Cheng: Right. So anyways, I will also talk about the solution right now. They don't want to sort of briefly talk about a solution called the scheduler activations model in the next lecture that. So right now what we're gonna do is, I'm going to go into 241 00:32:49.560 --> 00:32:57.690 William Cheng: We're going to go to the next part and see how to implement that. Right. So now we're going to talk with the strategy, you know, one level model to level model. And now we're going to talk about how to implement threads. 242 00:33:02.190 --> 00:33:09.900 William Cheng: Alright, so we're finished with the strategy was skipped a schedule activation model. And now we're going to talk about a simple throughout implementation. So again, this is very simple. 243 00:33:10.530 --> 00:33:16.140 William Cheng: So then talk about, you know, for the threat, what kind of data structure that you need was a financial blogger, as we talked about that already. 244 00:33:16.590 --> 00:33:21.720 William Cheng: We'll talk about a little more about switching and then we'll also talk about, you know, synchronization. 245 00:33:22.290 --> 00:33:29.730 William Cheng: Right. But I mean, these are all the topics that we talked about in chapter two. Right. Okay, so, so, so, so, so basically this is all going to talk about in chapter five. Yeah. 246 00:33:30.330 --> 00:33:45.930 William Cheng: All right. Oh, so, so, so one of the sort of most difficult step is to implement, you know, the implemented new tax. The challenge with implementing new taxes that you want to have to make sure that you know the new tax is actually implemented correctly. They under all kinds of concurrency. 247 00:33:46.950 --> 00:33:53.910 William Cheng: Okay, so, so, so what does that mean that the meat Ax is implemented correctly. Right. So when the application programmer right new Tesco. 248 00:33:54.090 --> 00:34:01.380 William Cheng: And then inside peek in between piece me like login. I love. There's a critical section call you got to make sure that the critical section code, you know, 249 00:34:01.650 --> 00:34:07.830 William Cheng: One. So actually, instead of civilization box. No other threat can be executing at exactly the same place. 250 00:34:08.100 --> 00:34:16.530 William Cheng: But there was no other side will also be executing that association box right so you have to implement the semantics of the new tax correctly and also the semantic condition variable. 251 00:34:16.950 --> 00:34:24.600 William Cheng: Okay, so we talked about the videos of the atomic operation for the condition variable of a piece or a condition with all that kind of stuff you have to implement them correctly. 252 00:34:24.870 --> 00:34:30.180 William Cheng: Okay, so. So what kind of self to have to worry about, you know, to, to, to make new tests implementation so difficult. Yeah. 253 00:34:30.780 --> 00:34:37.320 William Cheng: So this picture sort of summarize it. Right, so, so, so let's say that our thread is the one that's going to call you tax function and this one will be the pink that 254 00:34:38.310 --> 00:34:40.080 William Cheng: Guys, and this guy is what we're gonna do, we're gonna 255 00:34:40.830 --> 00:34:48.510 William Cheng: The way we do this is that we're going to try to access some data structure inside of critical section here. So we're going to call piece of new tax law. We're going to go piece of us out in LA. 256 00:34:48.720 --> 00:34:52.560 William Cheng: The code in the middle over here is going to be the critical section called my right here. 257 00:34:53.370 --> 00:34:58.290 William Cheng: That. So in this case, who do we have to worry about that might be competing with us for the same new tax. 258 00:34:58.710 --> 00:35:06.690 William Cheng: Guys over here we're sort of trying to pitch over here 1234 number one over here is that if we if the data structure that we're modifying over here. 259 00:35:07.140 --> 00:35:19.410 William Cheng: Okay, so say if the data structure over here that will modify over here is also a data structure that used by the interrupt handler. Then we got to make sure our new taxes implemented correctly so that the interrupt handler will not be able to hurt us. 260 00:35:20.820 --> 00:35:26.310 William Cheng: Okay, so, so he said he will handle over you're going to access some data structure if that data structure just happened to be the one 261 00:35:26.760 --> 00:35:30.510 William Cheng: In the inside of critical section. How do you make sure that you don't interfere with each other. 262 00:35:31.080 --> 00:35:35.640 William Cheng: OK, so the solutions over here is that when we call piece at a time slot. We need to watch out for the interrupt service routine. 263 00:35:36.150 --> 00:35:43.200 William Cheng: Okay, because if we don't, if we don't take care of it. We're going to end up, you know, inserting web servers again, we're going to end up access to the same data structure over here. 264 00:35:43.740 --> 00:35:58.500 William Cheng: You know as the as the sale critical section code that number to over here is going to be another threat right, this will be another thread, you know, are running, running, is that the same CPU over here, right. So again, we're juggling, you know, so, so, so, so we're gonna do 265 00:36:00.090 --> 00:36:08.910 William Cheng: We're going to do first switching right you're running out of CPU over here. And then you're going to give up the CPU voluntarily to give it to another threat or maybe you get a highway interrupt. 266 00:36:09.600 --> 00:36:23.400 William Cheng: The timer interrupt instead of coming up, we're going to switch to another threat it. This is not thumb thumb very, very carefully. It is possible that you know you're in the middle of the piece of metadata and now the second, third, start executing and going to mess up your data structure. 267 00:36:24.570 --> 00:36:34.410 William Cheng: Okay. So, therefore, we also need to make sure that you know when we implement on new tasks you know any competition from another thread running at the same CPU. We're going to make sure that our implementation over here to say 268 00:36:35.400 --> 00:36:41.280 William Cheng: That. All right, so this is a little different from festivity because we're actually we're talking about implementing so let's go 269 00:36:41.670 --> 00:36:45.030 William Cheng: All right. The other thing we have to worry about is that what if I have multiple CPU. 270 00:36:45.450 --> 00:36:51.780 William Cheng: Okay. In the second CPU over here. They can also handle interrupt independently, right, because when I have multiple CPU, I can actually enter 271 00:36:52.080 --> 00:36:59.220 William Cheng: interrupt the see the CPU independently. So, so if I only block out the interrupt inside my CPU. It is possible in another CPU. 272 00:36:59.610 --> 00:37:02.040 William Cheng: Inside of you observers. Today I'm going to enter modifying the same data. 273 00:37:02.490 --> 00:37:13.080 William Cheng: Well, so therefore, when I implement my new tax. I also need to make sure that another CPU cannot interfere with my operation over here. So, so, so another CPU CPU can be in the right context or can be the initial contacts. 274 00:37:13.290 --> 00:37:16.560 William Cheng: No matter what context. The other CPU and it will not mess me up over here. 275 00:37:18.000 --> 00:37:24.810 William Cheng: Okay. So, therefore, you know, when we try to implement, you know, our new tasks. We want to make sure that all these four kinds of concurrency, you know, 276 00:37:25.350 --> 00:37:31.560 William Cheng: That we sort of consider all these four kind of concurrency, so that the operation of the, of all the other 277 00:37:32.070 --> 00:37:38.370 William Cheng: All the other interrupt service routine, they cannot harm us. Okay, we're going to make sure I'm you types implementation is correct that way. Yeah. 278 00:37:39.060 --> 00:37:43.890 William Cheng: Alright. So as we look at the you know the the implementation over here, then it will be more clear. 279 00:37:44.700 --> 00:37:53.160 William Cheng: Alright. So the way we're going to do this is not with us we'll take a look at the simplest case first. So what is the simplest case, case, right, the simplest case over here is called the street threads case. 280 00:37:53.430 --> 00:38:02.280 William Cheng: Okay, straight. So that's over here is that we only have threads or we don't have interrupts. Okay. So, therefore, we don't have to worry about the interrupt service routine competing with our threat. 281 00:38:03.300 --> 00:38:13.200 William Cheng: Okay, so we're going to assume that we have no interest. Right. And also we're going to assume that we only have one CPU. So we don't have a secondary view. So in that case, the only you're the only thing that can interfere with operation is going to be another slide. 282 00:38:14.640 --> 00:38:22.440 William Cheng: Okay, so, so, so now the question over here is that under multithreading without Europe and, with only one CPU. How do we implement a new tag. So that's always say 283 00:38:23.340 --> 00:38:28.830 William Cheng: That right so we hear that story threat that the filters over here is that everything happened in the threat contacts. 284 00:38:29.040 --> 00:38:35.400 William Cheng: There's no interrupt contacts so there's no Iraq and when there's no interrupt this means that there's no preemption what what is preemption. 285 00:38:36.030 --> 00:38:42.750 William Cheng: So preemption is that, you know, again, we, we use a time slot scheduler where you start running out of CPU going to wipe out the timer when the timer goes off. 286 00:38:42.930 --> 00:38:53.250 William Cheng: We're going to yank out the CPU. We're going to give a CPU to another thing. So that's called preemption. Right. So if we don't have interrupt. Well, then in that case, there's no way for us to get an interrupt and so therefore there's no way for us to premium. 287 00:38:53.790 --> 00:38:59.130 William Cheng: Why is your third one is that the CPU. If you don't give up the CP voluntarily. You get to use the CPU forever. 288 00:39:00.870 --> 00:39:11.490 William Cheng: Okay, so, so under street third implementation over here. You know, there's no preemption. So if you don't give up a CPU your threat gets running out of CPU forever. So yeah, this is very, very important to understand 289 00:39:11.970 --> 00:39:20.370 William Cheng: Whoa, whoa, whoa, whoa, what's going on over here if you, you know, if you have 100 threat and if you have one. So it doesn't give up the CPU all the other 99 thread, they'd never get to run 290 00:39:21.570 --> 00:39:32.850 William Cheng: Okay, your kernel is like that. Okay, so, so, so, so you know way. Yeah, in a way, this is the real reason why Colonel threats feel different from user threat. When you write your one off to do you have to worry about keeping the CPU. 291 00:39:33.780 --> 00:39:40.980 William Cheng: Okay, you don't have to explicitly give out the CPU because, you know, if you use the CPU too long the operating system was will take you all the CPM give this up to somebody else. 292 00:39:41.550 --> 00:39:44.910 William Cheng: Okay, for our kind of our assignment this become a major consideration. 293 00:39:45.660 --> 00:39:51.660 William Cheng: Okay, because if you don't give out the CPU voluntarily while they're going to be big, big trouble. Right. So every time when you think about a situation 294 00:39:51.840 --> 00:39:58.230 William Cheng: You know, we used to when you run it when you start running a 13 so the CPU. The question that you should ask yourself, is that when is this going to give up the CPU. 295 00:39:59.070 --> 00:40:07.530 William Cheng: Okay. If the answer is, I don't know that you're in trouble. Okay. You need to know exactly when the soul give on CPU, because if it doesn't give up the CPU. Nobody else gets to run 296 00:40:08.550 --> 00:40:10.890 William Cheng: OK. So again, you know, this notice very important that 297 00:40:12.150 --> 00:40:22.140 William Cheng: Southern states. There's also there's only a CPU. So this is like your kernel assignment with driver equal to zero. I just mentioned that you said, Dr. Where you could write your start getting into ops. Well, then you have to worry about one 298 00:40:23.250 --> 00:40:30.810 William Cheng: Okay, so are we next assignment, we never have a second CPU. So, so in this case we won't have to worry about wanting to that. So once you say driver equal to one, then you have to worry about. 299 00:40:32.250 --> 00:40:44.250 William Cheng: Interrupt but if you keep driving equal to zero, you are doing straight threads. Okay. So, therefore I'm going to show you some CO of how to implement new tasks, guess what, you can copy those code into your kernel assignment. Yeah. Alright. 300 00:40:45.570 --> 00:40:47.010 William Cheng: So, so we're going to serve them to 301 00:40:48.030 --> 00:40:48.630 William Cheng: Sort of show you 302 00:40:50.610 --> 00:40:57.690 William Cheng: Should do with that. So number one, over here, I'm sure a lot of pictures over here. So we're gonna sort of draw a threat us, what Joe said like this. 303 00:40:58.050 --> 00:41:04.860 William Cheng: Okay, so remember a thread has a second job where I saw be. Here's the second to blah, I mean over here. I also just call it the thread object because you know again. 304 00:41:06.090 --> 00:41:10.980 William Cheng: That can be implemented user space and instead of Colonel so this doesn't really have to be a colonel data structures anyways. 305 00:41:11.190 --> 00:41:18.540 William Cheng: So I had to block the house around guy. They're all the same thing, right, and also every state has their own stack. Right. So they have, again, there's a stock over here. So, so 306 00:41:18.810 --> 00:41:24.300 William Cheng: So even though I know that there are separate data structure. Okay. But over here, I sort of draw them together as to save space. 307 00:41:24.870 --> 00:41:32.580 William Cheng: Now, so he's not a thorough job of your contacts area, the contact area point to the top of the stack. If this are sleeping right. So we saw that picture before. Yeah. 308 00:41:33.780 --> 00:41:40.590 William Cheng: Alright, so, so over here inside the Colonel, we're going to end up with a collection of fields over here. So this is what your current Oh my, look like 309 00:41:42.240 --> 00:41:50.640 William Cheng: Okay, so, so let's take a look at your picture very carefully. There's a global variable called current where that one points to the you know the points to a threat. 310 00:41:51.360 --> 00:42:01.290 William Cheng: Because, again, the third of your container control blog and also the stack of years. So I guess. So the current slide tells you which that is running out of CPU, right. So this is the one where the state of the third equals two running 311 00:42:01.980 --> 00:42:10.500 William Cheng: Backs. And then we'll have a Q A Weber cucu run queue instead around Q is a list of thoughts, all these threads that are waiting for the CPU. So therefore, they're all in the running state. 312 00:42:11.880 --> 00:42:18.840 William Cheng: Okay, and then the rest of the code over here it's again it's a bunch of cues, right, because every threat when they're sleeping, they have to slip into the queue. So what other cues are there. 313 00:42:19.050 --> 00:42:24.690 William Cheng: Well, there's new tax you number one. There's we'd like to nominate lots of new tax here there's as many as you have new taxes are the Colonel. 314 00:42:25.080 --> 00:42:36.000 William Cheng: They're also as many IoT devices so i o que as the IoT devices over here. There is a huge number one. Okay, number two, lots of other different tools over here. They're all over the place and every Q OBS multiple threads are slipping on that. 315 00:42:36.870 --> 00:42:40.350 William Cheng: Okay, so you're getting your kernel. Once that is running out of CPU and that will be this. 316 00:42:40.770 --> 00:42:48.540 William Cheng: All the other thing they are all sleeping in some kind of acute right except that you know the one that was sleeping, the wrong key. They're ready to run. They're not waiting for anything. 317 00:42:48.720 --> 00:42:53.430 William Cheng: While the other side. They are all waiting for something they're waiting, if you sleep in a meat AX you you're waiting for you guys. 318 00:42:53.640 --> 00:43:00.930 William Cheng: If you sleep in a condition barbecue you're waiting for a condition to be signal if you're waiting. You're just leaving an I. O que you're waiting for completion interrupt. 319 00:43:02.130 --> 00:43:10.020 William Cheng: Okay, so this is what you know, so, so, so this is where the colonel guy. So when you're doing your assignment is also look like this. Right. So, what you should do is that 320 00:43:10.470 --> 00:43:13.590 William Cheng: Anytime when you hit a breakpoint. So your current. Oh, you said where all my threats. 321 00:43:14.520 --> 00:43:24.300 William Cheng: Okay, you need to be able to know who is the parents that who is in the wrong que who was in all the other girl, you need to be able to know where all the assets are and then if a thread is inside this 322 00:43:25.050 --> 00:43:32.610 William Cheng: One of the q over here, you should you should ask yourself, who's going to wake them up, right, because if you don't wake them up, they never get to run or so, again, when you 323 00:43:33.330 --> 00:43:40.680 William Cheng: Go woken up, it can remove on one of these Q and get added to the rank you okay. It doesn't go you know become the cursor right away because somebody else is running out of CPU. 324 00:43:41.910 --> 00:43:49.380 William Cheng: Okay, so for every day, you need to you need to think about where is it, how does it get moving to the run killer. How does it execute her 325 00:43:49.560 --> 00:43:56.340 William Cheng: And when they finish, or just executing code inside of CPU where it's going to sleep next. Okay, or if this was going to die. You know, where is it 326 00:43:56.790 --> 00:44:02.160 William Cheng: Where's it gonna die. So eventually is going to cause some kind of, you know, pizza access. So I guess in colonel. It's called case the exit. 327 00:44:02.670 --> 00:44:04.650 William Cheng: Or as a case where x is piece of x is the same thing. 328 00:44:04.890 --> 00:44:16.170 William Cheng: Except one is used to spare one inside of Colonel so so eventually your friends going to go a call call call case to exit and then it will go into the zombies day once they go into the zombie state. It doesn't sleep in the queue anymore because they will never get to execute again. 329 00:44:17.400 --> 00:44:26.250 William Cheng: Right. So why does it. Why does it sleep inside of key, right, because he got some point, you gotta wake it up when you wake it up, you gotta move that says that threat from that Q into the wrong cues, so that this way. We'll wait for the CPU. 330 00:44:27.690 --> 00:44:34.080 William Cheng: Okay, so every day. You need to think about how it's going to go to sleep has gonna go walk, walk in, or how does it get you're going to sell terminate. 331 00:44:34.800 --> 00:44:38.430 William Cheng: That. So that's, you know, that's my thinking about the life cycle of all your threads. 332 00:44:38.670 --> 00:44:47.850 William Cheng: And for your kernel assignment for your current one. So remember all the first procedure or almost all the first piece procedure are written for you already. And they're all inside the favorite test dot C code. 333 00:44:48.840 --> 00:44:56.520 William Cheng: OK. So again, it's imperative that you try to read the code there in the beginning of won't make sense at all. Again, if you are, if you're confused semina that 334 00:44:59.340 --> 00:45:08.070 William Cheng: Alright, so, so, so let's take a look at the, I guess I mentioned this picture before I so if your friend is sleeping inside a thread object or the third control blah, there's a contact area. 335 00:45:08.280 --> 00:45:15.120 William Cheng: There's a bunch of CPU register. One of the register is a start point or the stock point to point to the top of the stack. If you know this thread is sleepy. 336 00:45:15.660 --> 00:45:25.020 William Cheng: Okay, so now we can actually sell know we know about run queue, we can actually see an improved version of the switch function, right, because the switch function. One of the arguments over here is going to be a thread. 337 00:45:25.410 --> 00:45:34.230 William Cheng: So now we know where to find this thread that you find a thread inside around Q there. So, therefore, this is the next version of the switch function is going to be cause stress which 338 00:45:35.070 --> 00:45:40.170 William Cheng: Now, so now when you're ready to give up the CPU, it will call us or so in this case, you don't need an argument. 339 00:45:40.920 --> 00:45:47.610 William Cheng: Okay, so what you would do is that when you are ready to go to sleep. Why would you go to sleep. Right. So for example you copy. So New types active you text is not available. 340 00:45:47.790 --> 00:45:55.470 William Cheng: When you meet that it's not available, you're going to call switch to to give out of CPU and also right before you call us which okay you're going to add yourself to the new tax. Q. 341 00:45:56.370 --> 00:46:01.110 William Cheng: Okay, so would you always do that. You add yourself to a queue and then you call Salesforce to give up the CPU. 342 00:46:01.890 --> 00:46:09.810 William Cheng: Now, so let's take them over the implementation over here, this is very similar to the switch function, except that, you know, you go to the rank you to find your thread that you're going to switch CPU to 343 00:46:10.140 --> 00:46:18.480 William Cheng: That. So, therefore, what we do over here is I'm going to call we're gonna call it a few people around you and this one will return to you a threat right so in the wrong key over here. There's a bunch of sleeping and 344 00:46:18.900 --> 00:46:23.910 William Cheng: You're going to take the first slide over here. You're going to DQ at this will be the next right. Next, whereas a local variable right here. 345 00:46:24.150 --> 00:46:28.020 William Cheng: And then you say the old current which is local variable over here to be the current so that 346 00:46:28.290 --> 00:46:37.710 William Cheng: Guy because now you're going to give the CPU to the to the to the next slide. So, therefore I'm going to say all current equals to the current were and then the current third over here is going to be equal to nest and now I switched these 347 00:46:38.850 --> 00:46:43.800 William Cheng: Switching these these global variables over here and then I will call this function called smart contracts. 348 00:46:45.000 --> 00:46:59.040 William Cheng: Okay, so what's what color is over here, is that what it will do is that it will save all the CPU register into the first argument over here. Okay. And then he will take all the arguments in the second, it will take all the building. The second argument and I put it back inside the CPU. 349 00:47:00.660 --> 00:47:10.170 William Cheng: OK, so the the switch function that we saw before. What it does, it, it only deal with the stock pointer. But now you're dealing with all the, you know, you know, you're dealing with all the CPU register over here. 350 00:47:10.320 --> 00:47:18.600 William Cheng: So again, the first argument is all current what is all current right all current equals to the current slide over here. So the third that's calling this function. So let's say this is a 351 00:47:18.990 --> 00:47:28.530 William Cheng: Guy. The other way is to be over here now all current is going to be thread. He said he has a data structure over here. So we're going to say the CPU contacts into the first argument and now there is going to go to sleep. 352 00:47:29.580 --> 00:47:33.450 William Cheng: Okay. And the next slide over here is going to be thread be right because we're giving the CPU to 353 00:47:33.690 --> 00:47:43.560 William Cheng: Be over here. So please come this area. We're going to take all the CPU register in this argument over here, put it inside the CPU. So again, in the middle of this function we give the CPU from threads ready 354 00:47:45.030 --> 00:47:50.460 William Cheng: Okay, so when this function return the basic idea will be here is is that now we're going to be in thread these contacts. 355 00:47:51.570 --> 00:47:59.310 William Cheng: OK. So again, this function is very similar to this. Which ones that come in through today over here. Once that goes out from the perspective of the operating system. 356 00:47:59.730 --> 00:48:02.430 William Cheng: You know, upon the from the perspective of the system. Okay. 357 00:48:03.390 --> 00:48:09.930 William Cheng: All right, so in the in the Phoenix girl I there's a function costs contracts which that's something I saw contacts. I mean, you know, 358 00:48:10.320 --> 00:48:14.880 William Cheng: So the textbooks are talking about these things in general term he winnings, they have different function names. Okay. 359 00:48:15.000 --> 00:48:24.510 William Cheng: You should look for a function like this, you know, look for the word contacts and try to see what they are and then read the code over here to see exactly how you save all the CP register into, you know, 360 00:48:25.470 --> 00:48:32.520 William Cheng: Into the first argument and then take the data from the second argument over here and restore them into the CPU, then 361 00:48:34.140 --> 00:48:40.590 William Cheng: Alright, so, so now we have a new switch function. Now we can actually see the implementation of a new tax law under history threats. 362 00:48:41.010 --> 00:48:45.630 William Cheng: That. So according to the textbook. This is how the employment tax law against threats. 363 00:48:46.080 --> 00:48:48.270 William Cheng: We don't have been around. We also only have one CPU. 364 00:48:48.540 --> 00:48:58.680 William Cheng: That so through a over here. So I said, it's got copies of meat, I thought. Right, so, so, so again inside the new tech data structure. There are two things. What does it mean attacks Q and the other ones to say whether the new tax law or not. 365 00:48:59.580 --> 00:49:05.760 William Cheng: OK, so the new text data Sergio has only two things and add there's a queue. And then there's a variable, right. So how do you want me to stop. 366 00:49:06.210 --> 00:49:18.300 William Cheng: Guy. So you're going to check whether the new tax law if the text is not locked. What would you do if the music is not loud. You said new tax law equal to one, you return from piece of a phone call from your tax law and now you're on dummy tax. 367 00:49:18.930 --> 00:49:28.050 William Cheng: Okay. So in this case, you also, it doesn't fall asleep, you call pod. Call me tax on it didn't block in return right away. So now you go and execute you go execute a critical section called 368 00:49:29.310 --> 00:49:30.810 William Cheng: Okay, is this implementation. Correct. 369 00:49:32.010 --> 00:49:39.570 William Cheng: Oh yes right when you call piece of new tech stack to the meat that's available you lock it and then you return and now you have any new tax law. So, therefore, you know. So, so far as correct 370 00:49:39.990 --> 00:49:44.640 William Cheng: One of the meetings is not available. So in this case, new top lock is true, that means there's somebody else on the new tax. 371 00:49:45.180 --> 00:49:49.230 William Cheng: Okay, so in this case what I will do is I will all myself to the new tax you who's myself. 372 00:49:49.470 --> 00:49:57.300 William Cheng: Myself is the current our current setup is going to be through as Ray is the one that called assumption, right. So I'm the one that's running out of CPU, so therefore I am current threat. 373 00:49:57.900 --> 00:50:03.300 William Cheng: That. So what I would do is I will add myself to the meat AX queue and then I will call that switch to debug CPU. 374 00:50:04.680 --> 00:50:14.220 William Cheng: Right. So again, this is the way that you must cost my switches that you add yourself to a Q first which is that right here. And then you call that switch to give up the CPU and now yourself a fall asleep. 375 00:50:16.590 --> 00:50:21.960 William Cheng: Okay, so later on when somebody wakes you up with somebody like you know what happened. Right. So the first week over here, look at the function call. So you can 376 00:50:22.170 --> 00:50:26.370 William Cheng: Switch to get through the fall asleep. Later on when you wake up, you're going to return punts I switch 377 00:50:26.730 --> 00:50:35.010 William Cheng: Raza when you were talking about. So I switch. Where do you go you return from new tax law over here. So hopefully, at that point, we're gonna we're going to verify that when you return from what we hear you don't have the new tax law. 378 00:50:36.540 --> 00:50:39.870 William Cheng: Okay, so, so, so if that's true, then we know that this implementation is correct. 379 00:50:41.280 --> 00:50:50.610 William Cheng: Right, right. How do you implement new testament law. So I'm going to assume that you don't have any bugs in your code, right. So when you call me text on law. So let's say a call me a lot. What 380 00:50:52.260 --> 00:50:58.290 William Cheng: That's called this way before. Now, right. So when you confess with you, but the CPU to be three B's gonna call me it has on Lok 381 00:50:59.670 --> 00:51:10.170 William Cheng: Okay, oh sorry therapy is the one that actually owns a new tax, right. So, so he's gonna be running around, only the new tax at some point. So if he's done with a new tax done with the critical section call. So what he would do is it will call me test a lot 382 00:51:10.620 --> 00:51:16.950 William Cheng: Of guys. I mean, this guy is what it will do is that they will look to see if the new tattoos empty or not. If the meter excuse empty. What, what should you do 383 00:51:17.610 --> 00:51:25.650 William Cheng: While so if the mutants few is empty, then it can really give them new types of anybody else. So in this case, it was said the log equal to false and it will return from the function right away. 384 00:51:26.430 --> 00:51:34.740 William Cheng: So you'd have a lot is a non blocking call the thread bo bo color what it called me. He will return right away, and it will start still start executing inside of CPU. 385 00:51:35.220 --> 00:51:41.670 William Cheng: Okay if nobody's waiting in a new tax few over here, though. What it will do is that he was simply said the law could be false. And now nobody owns a new tax. 386 00:51:42.630 --> 00:51:49.560 William Cheng: That what if somebody actually seeing them. You talk to you over here, right. So in this case, what it needs to do is to unblock that Q again. How do you block the queue. 387 00:51:50.010 --> 00:51:57.990 William Cheng: Right, so, so, so, so, so you need to unplug the threat. Right. So how do you take the thread that's at the head of that. Q And you move into the wrong. Q. 388 00:51:58.560 --> 00:52:06.630 William Cheng: OK. So the code, code over here is that you're going to DQ a que de de que a slap on the new text you and there is going to include that sweat into the wrong. Q. 389 00:52:08.610 --> 00:52:19.170 William Cheng: Okay, so, so this is how we I'm blocking so right you remove it from the new tax you and then you appended to the run queue and now again your function return right away. Okay. So now is the new tax law or not. 390 00:52:20.700 --> 00:52:29.550 William Cheng: Okay, so. So in this case, right. So since threat be on mute. So we know that new tax law over here is a lot over here is going to be for the one right. So when you return from this fancy and lock is still one 391 00:52:29.970 --> 00:52:41.070 William Cheng: Okay. Looks like there's a bug in this coat. Okay. But as it turns out that this is actually the correct implementation, because let's say that the thread that you wake up over here. So a sweater over here is get get get get get get 392 00:52:42.030 --> 00:52:49.800 William Cheng: Get moving to run to that. So in this case, you know, stripy conditionally executing that the CPU at some point. So happy voluntarily give up the CPU. 393 00:52:50.130 --> 00:52:57.960 William Cheng: Why are you so happy give on the CPU or maybe he's gonna wait for him you tax and none of your tax. Maybe it's going to I operation. Maybe he's going to call you sleep. For example, I will go to sleep. 394 00:52:58.230 --> 00:53:06.780 William Cheng: When it does that, we're going to women DQ itself on the wrong queue. And then we're going to run it. If it turns out that this rather you to keep on Roku is going to be a what will happen. 395 00:53:07.290 --> 00:53:16.110 William Cheng: What's the is going to return on switch whenever we talk about stress which one were to go, it will return from from new tax law and it has to be tax law because look over here is equal to one. 396 00:53:17.940 --> 00:53:29.640 William Cheng: Okay, so look like. This is actually the correct implementation. Right. So when therapy. I love the new tax meat, the meat has logged over here, equal to one, because at the time when slippy unlocked the new tax it passes the new tax to throw a 397 00:53:31.050 --> 00:53:33.630 William Cheng: Okay, so that's why it's reasonable to keep lock, you would have one 398 00:53:33.930 --> 00:53:42.660 William Cheng: Guy It's almost like what you're doing a relay race when you're really, really raised you sort of give him you're holding you know holding that stick and give it to the other person. And that's when you give them your tax to another threat. 399 00:53:43.350 --> 00:53:53.430 William Cheng: Okay, so this way you continue to go to your style. Eventually when you go to sleep. The other, the other person. Keep Ronnie when that person start executing is out of CPU that person has a stake. So therefore, in that case, the new tag. 400 00:53:53.760 --> 00:53:57.210 William Cheng: The tag is still locked, and now the new tax is owned by threading. 401 00:53:58.740 --> 00:54:10.050 William Cheng: Okay, so, so, so in the end you know this implementation, as it turns out to be correct. And I just want to remind you over here that you can use code like this, your kernel one because this one is good for strength that 402 00:54:10.590 --> 00:54:18.630 William Cheng: Okay, so when drivers equal to zero, this this code will work right drivers even why why towards the end of today's lecture, we're going to see what you have to do with drivers. Yeah. 403 00:54:20.640 --> 00:54:24.600 William Cheng: Alright, so, you know, it's just taking a moment agent atomic 404 00:54:25.770 --> 00:54:35.670 William Cheng: Okay, as it turns out that this you know the answer is yes, because we are under the street value implementation with a single process with no you know up right so what. So whatever color you execute over here. 405 00:54:36.210 --> 00:54:46.110 William Cheng: You know, if you don't voluntarily give up the CPU you continue to execute inside of CPU. Right. So every instructions over here. They are all atomic. You don't have to be in a critical section to be atomic 406 00:54:47.550 --> 00:54:56.610 William Cheng: Okay, because if you don't give out the CPU, then all the instructions over here and there's no way for you to for the CPU to interrupt you. There's no way for another said execute because we are under the strength that assumption. 407 00:54:57.600 --> 00:55:05.490 William Cheng: Okay, so, so, so in this cold over here. Where do you want to think about the CPU, there's only one place of Ontario. Give us CPU and that's insights West, which 408 00:55:06.960 --> 00:55:20.490 William Cheng: Okay, all the others. So, you know, so far we only learn one way to give up a CPU. That's my calling switcher so now to be current graduate into switch. Okay, so if your thread doesn't industry fair assumption. If you don't go switch you get to use the CPU forever. 409 00:55:22.350 --> 00:55:29.430 William Cheng: Alright, so, so, so, so, so in all in this cut over here, this is the only place where things are not upon it. Right. But in this case, you know, if the meat. 410 00:55:30.030 --> 00:55:38.040 William Cheng: The meeting is locked by another. Why, therefore, you should give up a CPU and then in this way, you know, you wait for the new types of the unlock in the right way, by going to sleep. 411 00:55:39.150 --> 00:55:48.240 William Cheng: Now. Alright, so, so, so, as it turns out, even though this code might not look at tommy. Tommy because this call only works under the streets, the streets that assumption. Okay. 412 00:55:49.740 --> 00:55:52.290 William Cheng: All right, so this is a good time to break and next time we're gonna 413 00:55:53.070 --> 00:56:03.810 William Cheng: We're gonna take a look at our the multiple CPU case. Okay, so, so in this class. Most of the time we don't we don't talk about the multiple CPU case because every time we talk about multiple CPU things going to get a lot more complicated. 414 00:56:04.410 --> 00:56:07.080 William Cheng: Okay, so, so we're gonna we're gonna come back and take a look at this right