WEBVTT 1 00:00:41.010 --> 00:00:49.380 William Cheng: Okay. Hi. Welcome to lecture six. If you have any question please unmute the microphone and asks 2 00:01:08.040 --> 00:01:09.300 William Cheng: Can people hear me. 3 00:01:11.340 --> 00:01:11.670 Hardik Mahipal Surana: Yes. 4 00:01:12.210 --> 00:01:14.100 William Cheng: Okay, I just want to make sure 5 00:01:15.840 --> 00:01:17.130 Hardik Mahipal Surana: Can I start asking questions. 6 00:01:17.340 --> 00:01:17.910 William Cheng: Sure, go ahead. 7 00:01:18.390 --> 00:01:29.340 Hardik Mahipal Surana: Okay. Actually, I had a bit of confusion between what you meant by early entrant code, you mentioned in the lecture that when we consider multi threading code. 8 00:01:29.850 --> 00:01:40.500 Hardik Mahipal Surana: Reentry and and safety mean the same thing. And when we are running single threaded code by default or the code is thread safe, but it might not be re entered 9 00:01:41.010 --> 00:01:47.100 Hardik Mahipal Surana: Right. So I just want to understand what do we actually expect when we say code is oriented. 10 00:01:49.980 --> 00:02:03.810 William Cheng: Um, well, I mean, in this class. We don't really use that term, right, we use the word first safety. So we met. We were mainly focusing on multi threading right when people use retention. They just means that it's you know it's the code is sort of 11 00:02:05.760 --> 00:02:14.460 William Cheng: You know, safe to use without getting into some weird, you know that they're like I i I'm not sure whether it's very, very well defined. 12 00:02:15.330 --> 00:02:16.260 William Cheng: Okay, let's 13 00:02:16.740 --> 00:02:17.610 William Cheng: Have your code. 14 00:02:18.480 --> 00:02:24.630 William Cheng: Is that, is that re entered or just a bug in your code, right. So I see so 15 00:02:24.660 --> 00:02:27.960 Hardik Mahipal Surana: Yeah, so, so by default we follow only thread safety as a 16 00:02:28.080 --> 00:02:28.950 Hardik Mahipal Surana: As a metric right 17 00:02:29.640 --> 00:02:41.040 William Cheng: Yeah. So when I say safety, then it's kind of clear that if you have two threads that are running in parallel. And then there's some timing problem, then you know it's a race condition then then your code is not safe. Right. Okay. 18 00:02:42.510 --> 00:02:50.850 William Cheng: So I, I think, which is which is sort of focus on safety and not focus on reenter because it's we answer is I don't think is well defined. 19 00:02:52.200 --> 00:02:54.450 Hardik Mahipal Surana: Okay, another question I had is 20 00:02:55.890 --> 00:03:11.880 Hardik Mahipal Surana: When we are running when we acquire a new text lock and we want to execute a function within that within the lock. So does it mean that the entire function. And if the if the function is like is very big is the entire function run as one atomic operation. 21 00:03:12.360 --> 00:03:16.110 William Cheng: Yeah, yeah, anything between meathead lots and meter unlock 22 00:03:16.380 --> 00:03:25.050 William Cheng: This one atomic operation. So if you want to call 15 functions they are you know they're locked together in the atomic operation with respect to that new texts. 23 00:03:25.920 --> 00:03:28.200 Hardik Mahipal Surana: Okay. Okay, good. And 24 00:03:29.070 --> 00:03:35.160 William Cheng: So, so I just want to add right so like what our warm up to right once you lock the new tasks. You have to, you know, 25 00:03:35.490 --> 00:03:47.160 William Cheng: You have to read the clock. So that's the system call you have to print something out on the screen. That's the system call. So you're going to end up making quite a few function call. Right. But all these calls, they are actually pretty sure they are done in milliseconds. 26 00:03:49.020 --> 00:03:49.830 William Cheng: So it's not so bad. 27 00:03:51.210 --> 00:03:51.480 Hardik Mahipal Surana: Okay. 28 00:03:53.250 --> 00:04:00.990 Hardik Mahipal Surana: Okay, so another question I had was with respect to signals. So you mentioned that if a signal is currently blocked. 29 00:04:01.560 --> 00:04:16.080 Hardik Mahipal Surana: And the signal arrives, then it is pending. Right. And once the signal gets unblocked that time the signal is delivered. So I wanted to know, between the time when the signal is pending. And by the time it begins its delivery. 30 00:04:17.310 --> 00:04:19.680 Hardik Mahipal Surana: Bed where it's stored. How do we know 31 00:04:21.180 --> 00:04:28.050 Hardik Mahipal Surana: Once we start waiting for the signal again. Where do we read the pending signals from and how do we exactly what we're delivering 32 00:04:28.470 --> 00:04:31.860 William Cheng: Rice. So, so the pending signals help at the Colonel. 33 00:04:32.550 --> 00:04:42.720 William Cheng: Right, because the the signal generator inside the Colonel. So if there are not allowed to deliver what then then inside the code on they need to remember that, you know, when you unblock the signal. 34 00:04:43.230 --> 00:04:56.160 William Cheng: They need the colonel need to to to to deliver the signal. So I'm blocking signal. It's also going to be a system called I because we unblock the signal. You can use that to Colonel the Colonel, say, Oh, there's a pending signal. So what it will do is they will deliver that signal. 35 00:04:59.130 --> 00:05:05.160 Hardik Mahipal Surana: Okay, so is it a part of a different kernel data structure or is it part of the trade control block. 36 00:05:09.720 --> 00:05:21.180 William Cheng: Is it in the threat. So pending well so dependent signal that's PR process. So it's not really in the threat control blog. So I mean, everything is reachable from the process control blog right so 37 00:05:21.600 --> 00:05:35.760 William Cheng: The process control blog. It's the sort of the main data structure that represented process. So anything that happened with the process. So remember right you know he he is that the process when you try to deliver a signal you pick a random threat that has a signal on block. 38 00:05:36.570 --> 00:05:39.900 William Cheng: Can i. So, therefore, to remember that there's a pending signal has to be done. 39 00:05:40.560 --> 00:05:42.180 William Cheng: Starting with the process control, blah. 40 00:05:44.070 --> 00:05:48.450 Hardik Mahipal Surana: Okay, so I'm because I was trying to build an analogy between how 41 00:05:49.590 --> 00:05:53.760 Hardik Mahipal Surana: There are threads that are trying to acquire a new tax law and there are 42 00:05:54.480 --> 00:06:02.460 Hardik Mahipal Surana: signals that are pending. And then that which which need to be delivered. So when you explain new text you expand using the concept of civilization box where 43 00:06:02.670 --> 00:06:10.710 Hardik Mahipal Surana: If the threads outside which are waiting for to acquire the lock on The View Tex. They are waiting in a muted skew and we can 44 00:06:11.640 --> 00:06:22.650 Hardik Mahipal Surana: So similarly, if you try to build an analogy with signals signals when we say signal is Penny. Can we say the same thing that it's waiting in the mute sq like a similar analogy. 45 00:06:23.220 --> 00:06:28.230 Hardik Mahipal Surana: Um, I don't think so. And it gets unlocked it's picked up from a pure from somewhere. 46 00:06:28.500 --> 00:06:29.910 Hardik Mahipal Surana: And then it's delivered 47 00:06:30.510 --> 00:06:40.680 William Cheng: What so so signal is generated inside the Colonel. Right. So when when the signal get generated the operating system will have to memorize that the signal has been generated, but it's pending. 48 00:06:41.460 --> 00:06:46.320 William Cheng: Okay, so therefore somewhere inside the process control blog. We don't know where. Right. So the pros and cons of law. 49 00:06:46.530 --> 00:06:55.770 William Cheng: I mean, it's a data structure, but it also contains pointers. So once you start using pointer, you know exactly what store. It's really not that important. Because you get you can have a pointer to a pointer to a pointer. 50 00:06:56.010 --> 00:06:58.140 William Cheng: And eventually point to a place I store the signal. 51 00:06:59.070 --> 00:07:09.420 William Cheng: Okay, so. So what you would do is that instead of Colonel, they need to, you know, remember that that is pretty good signal is pending somewhere inside the data structure that's reachable from the process control, blah. 52 00:07:10.080 --> 00:07:22.050 William Cheng: OK. And then when you call the system called unblock the signal, they will, you know, walk down that data structure to find out whether you have signal pending or not. If you have a signal pending, and then the audiences and we'll figure out how to deliver deliver that signal. 53 00:07:24.300 --> 00:07:25.380 Hardik Mahipal Surana: OK. OK. 54 00:07:25.770 --> 00:07:31.530 William Cheng: I mean we we don't need to know exactly what we're we're store because you know that's implementation dependent 55 00:07:32.220 --> 00:07:42.570 William Cheng: Right, so we just need to sort of understand the concept that you know yeah there's a pending it's done in that process control box somewhere and then it's, you know, operating system implementation, they need to figure out exactly what to do. 56 00:07:44.460 --> 00:07:50.100 Hardik Mahipal Surana: Okay. And I had a question with respect to thread cancellation in slide number 49 57 00:07:50.850 --> 00:07:52.140 William Cheng: Okay, let me go there. 58 00:08:03.690 --> 00:08:04.860 Hardik Mahipal Surana: I think no. 59 00:08:05.460 --> 00:08:06.900 William Cheng: Threat cancellation. 60 00:08:09.720 --> 00:08:11.100 Hardik Mahipal Surana: Yeah, I think. 61 00:08:12.030 --> 00:08:12.660 William Cheng: Before that, 62 00:08:12.750 --> 00:08:13.350 Earlier. 63 00:08:15.660 --> 00:08:19.050 Hardik Mahipal Surana: From the lecture when I go into the lecture said slide number 40 minute 64 00:08:19.770 --> 00:08:22.290 William Cheng: Okay, so is this after this 65 00:08:23.190 --> 00:08:25.110 Hardik Mahipal Surana: Talk to this year. It's one of the code examples. 66 00:08:25.920 --> 00:08:28.950 William Cheng: Okay, yeah, so that's this guy. Yeah. 67 00:08:29.730 --> 00:08:32.550 Hardik Mahipal Surana: Yeah. So my question is, 68 00:08:35.220 --> 00:08:51.090 Hardik Mahipal Surana: Over here. What happens if we call cancel after get data item, but before insert. Is it because insert adjust as memory, memory operations does the Cancel get blocked until insert finishes. 69 00:08:51.570 --> 00:09:01.320 William Cheng: The cancel the cancellation is pending. Right. We use the same terminology right if you cancel this threat cancellations pending so when it gets so cancellation point, then he will say, oh, 70 00:09:02.910 --> 00:09:06.090 William Cheng: Have I been canceled it by being cancelled. Then I need to call Peter exit. 71 00:09:07.890 --> 00:09:14.970 Hardik Mahipal Surana: Okay, so there is no way the thread can get canceled before insert finishes its execution through the phone call. 72 00:09:15.000 --> 00:09:22.590 William Cheng: So we assume that you know we do the default thing, right. By default, the threats cancellation is enable and and it's a it's different. 73 00:09:23.820 --> 00:09:24.180 William Cheng: Yes. 74 00:09:24.420 --> 00:09:28.650 William Cheng: Okay. So, therefore, what you are right. What, what would this record cancel right here. 75 00:09:29.730 --> 00:09:34.650 William Cheng: You know, it's going to continue to execute coding, sir, because there's no cancelation point in that right 76 00:09:34.770 --> 00:09:35.070 Hardik Mahipal Surana: Okay. 77 00:09:35.280 --> 00:09:44.250 William Cheng: So there was. There's no way for it to get to the act on cancel because there's no cancelation point and then when you get the printer printed a venture is going to call right and right is a cancellation point 78 00:09:45.690 --> 00:10:02.790 Hardik Mahipal Surana: I see. So, one more question is at any cancellation point the prefer exit is called before that cancellation point gets executed or after that. So for example over here will cancel, will the thread cancel after printer has completed execution or before it. 79 00:10:03.330 --> 00:10:12.810 William Cheng: Well, I mean, it will make sense that, you know, in the operating system implementation of right they will check to see if there's cancellation pending first right 80 00:10:13.830 --> 00:10:22.560 William Cheng: Okay, because if the function is going to do a lot of stuff is gonna erase the disk, you know, then, then you want to cancel the threat before it does that go 81 00:10:22.650 --> 00:10:22.830 Yeah. 82 00:10:24.330 --> 00:10:27.450 Hardik Mahipal Surana: Yeah, that's all the questions I had. Thank you so much. 83 00:10:27.750 --> 00:10:30.720 William Cheng: Yeah, so, so, by the way, you know, if the My question to your 84 00:10:32.100 --> 00:10:46.800 William Cheng: You know, the question about the you were asking about the signal, you know, being pending away exactly where that information is stored. So, you know, if you're unsure, you know, please, you know, ask more questions. Okay. 85 00:10:47.580 --> 00:10:52.350 Hardik Mahipal Surana: Sure, yeah. So right now I'm just unclear as to how the implementation of this would work. 86 00:10:54.330 --> 00:10:55.500 William Cheng: Yeah, so 87 00:10:58.620 --> 00:11:04.290 Hardik Mahipal Surana: It will be stored somewhere and we always have a reference to where it is stored. But I just want to understand 88 00:11:04.980 --> 00:11:19.350 Hardik Mahipal Surana: What do, what do we mean when we actually store a signal. Do we because do we store like the signal type and where it should have been handled and how it works together along with the cancellation points so that it happens synchronously. 89 00:11:19.710 --> 00:11:27.720 William Cheng: Right, you can do anything you want, you can still as much information as you want. He wants to as little information as you want. So against different openings ism designer. 90 00:11:27.960 --> 00:11:35.280 William Cheng: They want to say we want to provide more features than they will store more stuff on the provide less feature but they want to run faster. They want to be lean and mean 91 00:11:36.150 --> 00:11:44.550 William Cheng: So, you know, operating system designer can have all these choices, right. So, so the answer is that it really depends on the implementation. 92 00:11:46.530 --> 00:11:47.460 William Cheng: Does that make sense. 93 00:11:47.580 --> 00:11:50.820 William Cheng: Yeah, and also exactly what it's doing. Right. 94 00:11:51.450 --> 00:12:01.380 William Cheng: If you store the information you know in, you know, starting from the process. No, blah. If your store that, you know, a pointer to a pointer to a pointer. Well, then every time you get there, you're going to go through three hops. 95 00:12:01.770 --> 00:12:03.600 William Cheng: That's going to be slower than one hop right 96 00:12:03.900 --> 00:12:14.190 William Cheng: Okay, so therefore you can say, well, I can put it inside the process control blog, then it will be faster, but in that case the process controlled by the data structure is going to become bigger so therefore you have a speed and time trade off. 97 00:12:15.300 --> 00:12:21.510 William Cheng: So it's all these kinds of stuff that that sort of detail of the implementation. So we don't really, you know, worry about that much. 98 00:12:21.780 --> 00:12:29.430 William Cheng: We just need to sort of have an idea of where things are. And then you know the the actual design of the appliances and they can take care of all these details. 99 00:12:30.570 --> 00:12:38.670 Hardik Mahipal Surana: Okay. So Vince a situation like this comes up, or how to go about taking design decisions on for the implementation. 100 00:12:39.030 --> 00:12:49.920 William Cheng: Yeah, you talk to your boss, you say, what is more important faster or, you know, less memory. There's always a trade off. Right. I mean, no. 101 00:12:50.970 --> 00:13:01.860 William Cheng: More. One of the things I sort of noticed that people, when when when people come to grad school and then they found out that everything is a trade off. There's no more, you know, this is the way to do it because you know there are other concerns. 102 00:13:02.850 --> 00:13:03.180 Hardik Mahipal Surana: Okay. 103 00:13:03.360 --> 00:13:10.380 William Cheng: And that's very natural. It's probably okay to say that there's no one way to do this, you know, they're different ways and 104 00:13:10.800 --> 00:13:14.220 William Cheng: Some of them are better this way. So I'm in a better that way. That's just very natural. 105 00:13:14.550 --> 00:13:17.700 William Cheng: I mean pretty much all the classes you're going to take in in grad school. 106 00:13:17.970 --> 00:13:30.150 William Cheng: Unless you have sort of an optimization problem you can formulate them using the equation you can solve it, then in that case. Yeah, you know, exactly, you know, what is the right thing to do. But then there are also some argument against doing something like that. 107 00:13:32.070 --> 00:13:33.750 William Cheng: So yeah, okay. 108 00:13:33.780 --> 00:13:34.380 Hardik Mahipal Surana: Thank you so much. 109 00:13:34.920 --> 00:13:35.340 Welcome 110 00:13:38.280 --> 00:13:39.030 Andrew Strimaitis: Hello, Professor. 111 00:13:39.210 --> 00:13:45.960 Andrew Strimaitis: Hey so earlier in the slides. You were talking about synchronous versus asynchronous signals. 112 00:13:46.650 --> 00:13:47.430 William Cheng: And yes, 113 00:13:47.460 --> 00:13:54.990 Andrew Strimaitis: You mentioned how there are sometimes security issues with asynchronous singles and are 114 00:13:55.170 --> 00:13:57.030 William Cheng: Not security. Right. So it's just 115 00:13:57.090 --> 00:14:02.100 Andrew Strimaitis: bugs. Bugs. Um, so I was hoping maybe you could 116 00:14:03.180 --> 00:14:18.540 Andrew Strimaitis: summarize then, like, maybe just the cost and the benefits of using asynchronous and synchronous because I remember we we talked a while about asynchronous. I'm just wondering, like, if there's maybe specific moments when just synchronous is better or maybe in fact it's it's worse. 117 00:14:18.840 --> 00:14:21.780 William Cheng: A synchronous, in my opinion, is always better. 118 00:14:22.080 --> 00:14:23.010 Andrew Strimaitis: always better. Okay. 119 00:14:23.190 --> 00:14:27.810 William Cheng: Yeah, because you know these slides that I'm showing you right here, right, that, you know, if you 120 00:14:28.740 --> 00:14:36.060 William Cheng: You know, so be because the the way politics implement signal delivery, they will pick a random thread and then they will, you know, follow that thread to deliver a signal. 121 00:14:36.810 --> 00:14:44.490 William Cheng: When they do when it does that, if, if that thread is in the middle of a system called that every system call you have to write it into an infinite loop. 122 00:14:46.110 --> 00:14:52.860 William Cheng: So that's really ugly right so you you don't want to write your code so that every time we make a system call you have to put inside of 123 00:14:53.100 --> 00:15:02.400 William Cheng: A little because there's a possibility that there will get politic deliver signal and now the system call will get boarded so you want to check whether the system has a board or now that's that's really annoying. 124 00:15:03.300 --> 00:15:07.680 William Cheng: Right, so therefore the right way to do it is that you want all threats to block all signals. 125 00:15:08.310 --> 00:15:20.880 William Cheng: Except for one thread that's unblocking that signal. Well, then in that case, you know that when the signal get deliver it will it will always get delivered to that. So that, and that's what I will you sick. Wait, so they will wait for the signal you know synchronously. 126 00:15:22.620 --> 00:15:26.790 William Cheng: Okay. So I think, I think that's the recommended way to do it. 127 00:15:28.620 --> 00:15:31.500 William Cheng: That BB BB because because we don't want to write infinite loop everywhere. 128 00:15:32.370 --> 00:15:35.160 Andrew Strimaitis: Right. Right. Okay. All right. 129 00:15:35.460 --> 00:15:45.270 William Cheng: Okay, so, so I guess this is the example for the racism call you put in an infinite loop and the next example is even worse. You know it's the right system call you also have to put inside of the sort of a sort of a info. 130 00:15:46.050 --> 00:15:50.340 Andrew Strimaitis: So the example on the screen right now is the example of asynchronous. 131 00:15:51.540 --> 00:15:52.440 William Cheng: Yes, yeah. 132 00:15:52.980 --> 00:15:53.280 Andrew Strimaitis: Okay. 133 00:15:53.520 --> 00:16:00.300 William Cheng: Right, because what happened is that, you know, when you in the middle of the right you'll throw will get borrow to deliver a signal. And now, right, what a board. 134 00:16:00.840 --> 00:16:11.280 William Cheng: And then in this case you I will return with you know you didn't write all the data on the desk. So, therefore, you have to see how many bites you have written down to this. And then you have to call right over and over and over again. 135 00:16:13.410 --> 00:16:24.960 William Cheng: Okay, so, so, so, so, by the way, racism call. It's kind of special so you know sometimes when you make the right system called a networking, you have to do this. Anyways, 136 00:16:25.920 --> 00:16:29.940 William Cheng: Okay, so, so, so, so, but but typically when you try to write to the fastest them. 137 00:16:30.690 --> 00:16:36.270 William Cheng: You should just call right once and all the data will go on to the desk and then I will return to say all the data has gone through this 138 00:16:36.720 --> 00:16:45.210 William Cheng: Okay, but again it depends on whether you're dealing with networking or up again this cause would only talk about networking. So, you know, we're not we're not going to focus on that. 139 00:16:47.160 --> 00:16:47.430 Andrew Strimaitis: Okay. 140 00:16:50.760 --> 00:16:51.420 Andrew Strimaitis: Thank you. 141 00:16:51.720 --> 00:16:52.440 William Cheng: Okay. You're welcome. 142 00:16:58.890 --> 00:17:06.960 William Cheng: Yeah, for example, you know, you can use the racism. Well, the right to the screen so so so so you started right data to to to display. 143 00:17:07.590 --> 00:17:21.750 William Cheng: Typically, you know, right, what right everything onto the screen. Okay, and then unless he was interrupted, you know, to deliver a signal that in that case it will it will return less number of bytes and you have to write again to to finish whatever you're writing 144 00:17:23.220 --> 00:17:27.510 Andrew Strimaitis: Okay, so since you have those slides open, can you go to Slide 25 145 00:17:28.230 --> 00:17:28.830 Okay. 146 00:17:32.250 --> 00:17:33.420 Andrew Strimaitis: So with this one. 147 00:17:34.440 --> 00:17:35.940 Andrew Strimaitis: synchronizing a synchrony. 148 00:17:36.300 --> 00:17:39.120 Andrew Strimaitis: Um, you have that line of the bottom that this is preferred. 149 00:17:39.360 --> 00:17:41.430 Andrew Strimaitis: Yes, but but this is 150 00:17:41.670 --> 00:17:50.670 Andrew Strimaitis: A method of trying to make asynchronous some form of of like a synchronous call you have the while loops. 151 00:17:52.260 --> 00:17:55.260 Andrew Strimaitis: So, so I'm confused. Is this actually preferred or 152 00:17:55.290 --> 00:17:59.760 Andrew Strimaitis: Is the preferred just trying to find some way of just doing synchronous from the ground up. 153 00:18:00.390 --> 00:18:10.740 William Cheng: Yeah, it's oh so. So this example. So to show you how to, you know, hundred block all the signals all the threats. Right. So in the main function as soon as you start your program you block signal everywhere. 154 00:18:11.400 --> 00:18:21.450 William Cheng: Right, so you brought signal in the main threat from this point on any child thread that you could you create, they will inherit the signal mass of the parents that so therefore everywhere. So, again, is blocked. 155 00:18:23.430 --> 00:18:29.550 William Cheng: Okay. So in this case, you know, every three you can just write your code. Normally, you don't have to put them into the infinite loop if you make a system call. Okay. 156 00:18:30.150 --> 00:18:42.060 William Cheng: So this is the the control see catching threat right so therefore inside this the you know the other this code over here. Again, most of the time the signal is blocked except inside this function right here segue. 157 00:18:42.480 --> 00:18:50.850 William Cheng: This is the only time the signal will get on block. So, therefore, you know that when when a signal get deliver it has to be delivered in the middle of this function call. 158 00:18:51.810 --> 00:18:57.870 William Cheng: So right now, your signal delivery become synchronous, right, because we know exactly which line of code, the signal will get deliver 159 00:19:00.870 --> 00:19:06.030 William Cheng: I mean, we don't know when it's going to happen. But we know that if it gets delivered it will be delivered right and this line of code. 160 00:19:09.480 --> 00:19:09.840 Andrew Strimaitis: Thank you. 161 00:19:10.350 --> 00:19:21.240 William Cheng: Okay. And again, the reason is that you know all this code that's running in another in another thread that code has a signal blocked so therefore it's impossible to follow this thread to deliver the signal. 162 00:19:30.180 --> 00:19:36.300 William Cheng: Gay. So for your warm up to. So again, what you should do is that as soon as at the beginning of main just blocks again. 163 00:19:36.930 --> 00:19:46.920 William Cheng: Okay, and then you create all your four threads that you join with all those formats. You also want to create a signal catching thread, just like this. And now in the right code like this, right. So when segue return 164 00:19:47.850 --> 00:19:54.120 William Cheng: You know what you should do is that you liked him, he attacks and do a bunch of stuff and you unlock the new tasks, instead of going into an infinite loop you should just quit. 165 00:19:54.510 --> 00:20:00.540 William Cheng: Usually just, you know, copy FedEx, it will have a break out of the infinite loop and then your signal catching thread. 166 00:20:00.960 --> 00:20:09.390 William Cheng: Will be dead. Right. So once this thread is dead. Well, now all your threads all have control see blocked so therefore the press Control C, Control C is just going to be competitive. 167 00:20:15.960 --> 00:20:17.730 William Cheng: It's going to become pending in definitely 168 00:20:17.820 --> 00:20:19.170 William Cheng: Right, and that's exactly what you want. 169 00:20:23.100 --> 00:20:24.150 Chao Xiang: A high professor 170 00:20:24.300 --> 00:20:30.390 Chao Xiang: Yes, I have a question about the context switching on page 55 171 00:20:32.970 --> 00:20:35.040 William Cheng: Page 55 on the slides. 172 00:20:35.730 --> 00:20:36.180 Yeah. 173 00:20:42.360 --> 00:20:49.050 Chao Xiang: Here, here it is that its global variable have fixed local, local adjust but 174 00:20:50.160 --> 00:20:55.170 Chao Xiang: Here in somehow implies local variable will change their address right 175 00:20:56.400 --> 00:21:04.320 William Cheng: So you mean this one I'll be a global variable are fixed in location in the address space or once you start running your program. They never change your address. 176 00:21:05.100 --> 00:21:07.800 Chao Xiang: Yeah, but how about local variables. 177 00:21:08.610 --> 00:21:23.610 William Cheng: Yeah. So over here, right, when when main course up these local variables are going to have one address, then the example that I gave in classes that one of main also call x right inside the function x over here, they call why and then inside the function, why they call sup 178 00:21:24.870 --> 00:21:29.460 William Cheng: Okay, so in that case when he called sub all these I end result, they will have a different address 179 00:21:30.690 --> 00:21:31.590 William Cheng: Does that make sense. 180 00:21:32.100 --> 00:21:35.850 Chao Xiang: Oh, so for the main thread that I have a will have a fixed address 181 00:21:36.630 --> 00:21:48.840 William Cheng: What yeah if may simply costs out right because the these are static variable, right. So we have a stack frame for me. I mean, here's a staff member may and when you call sub it will look like this. And the stack frame is going to have a 182 00:21:49.560 --> 00:21:55.170 William Cheng: You know, so in this example over here, or what main course up the sub is dinner the Stafford is going to be of a certain size. 183 00:21:55.560 --> 00:21:58.950 William Cheng: Okay, so therefore all the local variable i and resolve it will be sitting right here. 184 00:21:59.400 --> 00:22:05.610 William Cheng: Okay, but if main called X and X call wide, then in that case, we're going to have a slightly different picture. We're going to have main sitting over here. 185 00:22:05.820 --> 00:22:12.960 William Cheng: And then we're gonna have eggs and then we're going to have why. And then we're going to have sub let me clearly these addresses is going to be smaller than the addresses over here. 186 00:22:15.210 --> 00:22:21.840 William Cheng: So that's why the local variable, they can get different addresses depends on which functions, call them and how deep the stack is all that kind of stuff. 187 00:22:22.980 --> 00:22:30.750 Chao Xiang: So when we do context switching me all the variable is stored in the memory where they go to the disk. 188 00:22:32.460 --> 00:22:35.730 William Cheng: So the operating system will take care of that. Right. But the idea here is that 189 00:22:36.240 --> 00:22:46.170 William Cheng: You know, you need to think about the address space abstraction. Right. So, so your program, you should always think about you have the address space or all your variable live inside the address space. 190 00:22:46.530 --> 00:22:58.800 William Cheng: Okay, whether these variable are currently in memory on the desk. It's not your concern the ordinances, or make sure that if they're on disk. And when you try to use them the ordinances will bring them for the test into memory. So you don't have to do anything special. 191 00:23:00.720 --> 00:23:01.050 Chao Xiang: Okay. 192 00:23:02.340 --> 00:23:13.830 William Cheng: Whereas when you read your program. All you need to think about is the address space where I have local variable. I have a global variable, variable inside the heat. I need to manipulate all these variable so that my program will run correctly. 193 00:23:15.300 --> 00:23:20.700 William Cheng: Right. Because if you think about, you know, what will your program. Does your product is basically all it does is to change the variable values. 194 00:23:22.320 --> 00:23:24.450 William Cheng: At the end, you know, one more point you want to that's 195 00:23:24.480 --> 00:23:25.620 William Cheng: Pretty much all they do. Right. 196 00:23:27.120 --> 00:23:31.380 Chao Xiang: And I have another question at page 57 197 00:23:31.740 --> 00:23:32.340 OK. 198 00:23:33.810 --> 00:23:42.510 Chao Xiang: So the EP pointer is point to the next ep the next ep or the bottom of next three 199 00:23:44.760 --> 00:23:56.850 William Cheng: Yeah, so whether the top or the bottom and that this is just a notation. So over here, what I do is that you know if there's an address right here. If you use that address if you get a four by number from the address, you're going to get this number. 200 00:23:57.630 --> 00:24:01.350 William Cheng: Okay, so that's why I chose them at the at the top of that memory location. 201 00:24:03.240 --> 00:24:06.600 Chao Xiang: And even if he will always point to next PvP right 202 00:24:06.870 --> 00:24:07.710 William Cheng: Exactly, yeah. 203 00:24:08.940 --> 00:24:17.130 William Cheng: So that's, you know, the, the compiler needs to make sure that they generate code so that this is true. We're going to rely on the compiler to to make sure that this happens. 204 00:24:20.820 --> 00:24:23.760 William Cheng: There so so the picture over here is right. Here's one stack frame. 205 00:24:24.030 --> 00:24:36.480 William Cheng: And here's another stack frame. And here's another stock rain. So if you follow the EDP as I CPU, it will point to the next pointer that will point to the next point, or they'll point to the next pointer. So all the staff room I linked together in a single link lists. 206 00:24:41.520 --> 00:24:54.780 William Cheng: Every stack rank might be of a different size. Maybe there's some of them will have local variable that are very big. Some of them have local variable that very small so every stock room is the sizes, different. So it's a really strange linguists 207 00:24:56.790 --> 00:25:00.720 Chao Xiang: And another questions page 58 208 00:25:01.020 --> 00:25:01.890 Chao Xiang: That's between here. 209 00:25:02.790 --> 00:25:07.140 Chao Xiang: And here you give an extreme example about like 210 00:25:08.340 --> 00:25:13.770 Chao Xiang: The age case that we can only have he IP in one 211 00:25:14.790 --> 00:25:15.480 Chao Xiang: Frame right 212 00:25:15.990 --> 00:25:17.400 William Cheng: Even even the bottom one here. 213 00:25:19.470 --> 00:25:20.820 William Cheng: The example for the function 214 00:25:21.510 --> 00:25:22.140 Chao Xiang: Yeah yeah 215 00:25:22.650 --> 00:25:34.740 William Cheng: Yeah, because we don't need local variable another local turbo is not require function arguments not require so in this case MVP doesn't even have the point here, right. And then if we don't save any register, whether the only thing left is the IP. 216 00:25:36.150 --> 00:25:38.970 Chao Xiang: A why up not to use 217 00:25:40.080 --> 00:25:47.160 William Cheng: Yeah, so, so the reason you need EDP to point right here is to access local variable and access function argument. 218 00:25:49.050 --> 00:26:03.810 William Cheng: Okay, the local, you know, the local variable and the function argument. You can use a global address to to to access them right because we don't know the global address it depends on you know when you make the function call that they get different address every time. Right. 219 00:26:03.960 --> 00:26:07.650 William Cheng: So the way that we do this is that we're going to use a VP as a base pointer. 220 00:26:07.830 --> 00:26:13.440 William Cheng: We add address to it to access function argument and we subtract addresses from it to access local variable. 221 00:26:16.620 --> 00:26:22.110 Chao Xiang: So if there are no local variable and documents. You don't need even up to access them right 222 00:26:22.140 --> 00:26:32.280 William Cheng: Right, so. So in that case, I can have a BP pointed the next stack frame right so I don't have to save the context and later on after we store the contacts, because that will cost you machine instructions. So one thing that you can do is you can just skip that. 223 00:26:35.520 --> 00:26:38.100 Chao Xiang: Yes, yes. Okay. Yeah, I get it. 224 00:26:38.610 --> 00:26:49.080 William Cheng: Okay, so, so it depends on what kind of compile you're using. If you're using a smart compiler right then it will say, oh, if I don't have function argument if I don't have local variable. Well, in that case, I don't need to say dvd 225 00:26:49.410 --> 00:27:00.630 William Cheng: But if you use a very simple compiler, then it will say, I'm going to generate code sad VP anyways. And later on, I need to, you know, restore a VP. So in that case it will be a little slower but again it's not incorrect. 226 00:27:02.070 --> 00:27:09.150 William Cheng: Okay, so, so we're talking about over here, you know, what is the minimum stock for if it's a minimum stock where and what that you don't you don't need to say BVP 227 00:27:13.890 --> 00:27:15.570 Chao Xiang: Okay. Yeah. Thank you. 228 00:27:15.930 --> 00:27:17.250 William Cheng: Okay, yeah, yeah. 229 00:27:24.210 --> 00:27:25.260 Wookyum Kim: Oh Hi Professor 230 00:27:25.440 --> 00:27:25.800 Hey, 231 00:27:27.360 --> 00:27:37.980 Wookyum Kim: In Slide 21 232 00:27:40.350 --> 00:27:40.770 William Cheng: Yes. 233 00:27:41.880 --> 00:27:51.330 Wookyum Kim: Yeah, in here. Oh, we blocked the mask and then unblock it again so 234 00:27:52.110 --> 00:27:56.880 William Cheng: Yeah. So, this what you mean. This one is sit block. This one is six set mass is that the one you're talking about 235 00:27:57.870 --> 00:27:58.440 Yeah. 236 00:28:00.000 --> 00:28:03.630 William Cheng: Right. So over here, superblock meaning that we want to block the signal. 237 00:28:04.200 --> 00:28:11.760 William Cheng: Right, so we're blocking a cig alarm. Right. And then we save the previous signal mass in this local variable called oh set right here. 238 00:28:12.450 --> 00:28:19.860 Wookyum Kim: I mean, actually, we add that. I mean, seek accept that. So we're setting up the blocking some years right 239 00:28:20.460 --> 00:28:27.240 William Cheng: Yeah so so Sick Sad just manipulating this data structure is set up because a bunch of zeros. You said one of them to be a one. 240 00:28:28.080 --> 00:28:46.260 Wookyum Kim: Okay, and then set timer were there. And then after that, oh, delete that I mean that yeah I mean after to seek field set and seek to set that is a deleting the block kings. Right. 241 00:28:46.830 --> 00:28:54.720 William Cheng: Well, so again, uh, you know, this is just manipulating the data structure. So when you finish calling sick that Lisa, you're going to get a bunch of ones right 242 00:28:54.960 --> 00:28:58.320 William Cheng: Yeah, that one piece is equal to zero. So you're just changing the data structure. 243 00:28:59.730 --> 00:29:14.100 William Cheng: Okay, and then you get this pattern to six suspend what six spell will do is to take this pattern and copy them into the signal mask. Yeah, and all the one bizarre. We are blocking the signal. So the only signal that will be on blog will be sick a lot 244 00:29:16.500 --> 00:29:32.460 Wookyum Kim: Oh yeah so I kind of confused because the. Why do we need to like set up that in that. I mean, in the oboe lines like seek pro mask or sick at sets in there because 245 00:29:33.900 --> 00:29:38.910 William Cheng: Yeah, so, so, so over here, what we need at the top over here, I first want to block Ceylon. 246 00:29:39.600 --> 00:29:42.720 William Cheng: Yeah. Okay, so this is the way to block sing along. 247 00:29:44.130 --> 00:29:48.120 William Cheng: The lines of code right sick empty says sick as they're sick prognostic block. 248 00:29:48.360 --> 00:29:49.620 William Cheng: That's how you block a signal. 249 00:29:50.130 --> 00:29:50.610 Okay. 250 00:29:51.900 --> 00:29:52.440 Wookyum Kim: Then 251 00:29:53.160 --> 00:30:01.950 William Cheng: And then the you know the and then you then then then you start the alarm clock. And then the next three lines over here, sick feel sick, sick at least a six to spend 252 00:30:02.130 --> 00:30:15.180 William Cheng: What that's because the way six suspend work the success plan required this argument to be to look exactly like this. Okay, so I'll be here. We basically set up at the data structure to to be exactly what's required by six suspend 253 00:30:15.870 --> 00:30:16.470 Wookyum Kim: Okay. 254 00:30:17.250 --> 00:30:28.710 William Cheng: Yeah, because in the end, what we need to do we need to copy this into the signal mass and we only want to unblock the sick alarm signal. So therefore we have to set up these argument this way. So, this way we can use the argument to we can use the 255 00:30:28.740 --> 00:30:31.200 William Cheng: Set local variable costs assessment. 256 00:30:31.890 --> 00:30:34.860 Wookyum Kim: Okay, yeah, I got it. I think I got it. 257 00:30:35.130 --> 00:30:37.170 Wookyum Kim: Okay, and in slide. 258 00:30:37.200 --> 00:30:39.150 2525 259 00:30:44.730 --> 00:30:53.310 Wookyum Kim: Yeah, so I mean in in 24 he said that thread Brendan thread is randomly selected right 260 00:30:55.260 --> 00:31:01.110 William Cheng: Okay, so for all the thread that have the signal on block, then it's selected randomly. Yeah. 261 00:31:01.560 --> 00:31:04.920 Wookyum Kim: Oh, if there is a block, then it's not selected. I mean, 262 00:31:05.100 --> 00:31:11.880 William Cheng: What if the signal is if the signal is blocking a thread, then you you're not allowed to deliver the signal to that threat right because that's that is blocking the signal. 263 00:31:14.460 --> 00:31:19.380 Wookyum Kim: Oh, so I mean if the car is blocked, then it's attendings right 264 00:31:21.660 --> 00:31:21.930 William Cheng: Well, 265 00:31:22.830 --> 00:31:26.970 William Cheng: Okay, so this is positives. Right. The signal, I should go with a process. Okay, yeah. 266 00:31:27.090 --> 00:31:39.360 William Cheng: If the process has multiple threads one then there's extra complication or so for example if I if I have three threads over here. Right. Yeah. Okay. So, this one has a signal blog. This wireless signal on blog as well as a signal on block. 267 00:31:39.570 --> 00:31:49.560 William Cheng: So, not two threads at the same time block. Now when I tried to deliver the signal, I need to choose one threat and borrower to deliver the signal, since there are two of them is on blog. I'm going to choose them at random. 268 00:31:50.370 --> 00:31:52.080 Wookyum Kim: Oh, okay. So, 269 00:31:52.530 --> 00:31:58.290 William Cheng: To use the one that has the signal Brock, right, because that's the one that says, I don't know. I blogged the signal, don't bother me. 270 00:31:59.370 --> 00:32:01.350 Wookyum Kim: Oh, 271 00:32:02.100 --> 00:32:08.580 William Cheng: Raza out of all the threads that have the signal Brock does the operating system get to choose one or the pizza library get to choose one. 272 00:32:09.240 --> 00:32:23.880 Wookyum Kim: Or so if there is just a once read, then the lock that blocked secondary is pending improvement of that. But if there is a multiple threads, then it will choose randomly from that. 273 00:32:25.200 --> 00:32:26.820 Wookyum Kim: Stress daddy's unblocked right 274 00:32:27.060 --> 00:32:31.740 William Cheng: Right, right. So, so if I brought this one as well. Right. So this is block and this is blog right 275 00:32:31.950 --> 00:32:36.540 William Cheng: Well, then, in this case, I don't have a choice or I have to choose the set to deliver the signal. 276 00:32:37.290 --> 00:32:38.700 Wookyum Kim: Of okay 277 00:32:38.940 --> 00:32:43.050 William Cheng: Okay. So, so what this code is doing over here is that initially. I'm going to block everybody 278 00:32:43.290 --> 00:32:43.800 Wookyum Kim: Yeah. 279 00:32:44.010 --> 00:32:49.620 William Cheng: So if I generate the signal, then the signal become pending and we either because there's no threat to deliver the signal. Right. 280 00:32:50.130 --> 00:32:56.190 William Cheng: As soon as I change one of them from blocked on blog or then in that case I will have to deliver it, you know, using this to that. 281 00:32:56.970 --> 00:32:57.780 Wookyum Kim: Okay, got it. 282 00:32:57.960 --> 00:33:00.120 Wookyum Kim: Yeah. Okay, thank you very much. 283 00:33:00.390 --> 00:33:00.600 Okay. 284 00:33:04.980 --> 00:33:05.310 Wookyum Kim: So, 285 00:33:05.460 --> 00:33:15.330 Lalit Gupta: I have a question. So my question is, can we assume that the Peter exit will pop all the items in the corresponding to the stack of 286 00:33:16.440 --> 00:33:20.610 Lalit Gupta: Peter Tina pop automatically or can we are, we can envision that 287 00:33:21.210 --> 00:33:23.130 William Cheng: I'm a comically 288 00:33:25.800 --> 00:33:31.890 William Cheng: That part. I don't know about automatically right because the idea about when you call pizza exit is is going to call all those function. 289 00:33:32.790 --> 00:33:37.230 William Cheng: So automatically if you have the new tax law right like the example that we saw before. 290 00:33:37.800 --> 00:33:51.810 William Cheng: Then, then one of the function inside the cleanup stack is piece of me ties on lock. Right. So once you finish calling piece of me that allow your house you're outside of the critical section, then there's no more atomic operation. 291 00:33:52.950 --> 00:34:14.130 Lalit Gupta: Okay, so you have to be careful of the order of the Pops, so that we always have the Nvidia NC enabled so that if something is if let's say in the in the pop stack. If we unlock it, we have to make sure that if our data structure is is in a state that if other 292 00:34:15.510 --> 00:34:23.700 Lalit Gupta: Tries to access it, it will like have the state in an invariant sheets. For example, you should not free it before unlocking 293 00:34:24.240 --> 00:34:34.230 William Cheng: Well yeah, I mean, you know, so we would call this a cleanup stack. Right. So if it's a stack that you only you can only do last in first out 294 00:34:34.830 --> 00:34:45.360 William Cheng: There's no way that would do it in any order that it wants right so we call push if you call push a, b, and c when you pop it, you're gonna you're gonna pop. See, and followed by papi followed by pop eight 295 00:34:46.500 --> 00:34:48.120 William Cheng: Right, so it will follow that order. 296 00:34:49.230 --> 00:34:59.970 William Cheng: Okay, so when you try to push up onto the stack. You have to carefully, you have to be careful how you pushed up onto the stack, because you know that when when when when things get popped off, they will be exactly the reverse order. 297 00:35:01.200 --> 00:35:01.770 Lalit Gupta: Okay. 298 00:35:02.460 --> 00:35:11.550 William Cheng: Okay, so, so, so when you write your code, you gotta, you gotta be careful. You got to think about, you know, whether this this order will be okay if this order is not okay, well then, then you shouldn't read your code that way. 299 00:35:11.700 --> 00:35:14.280 Lalit Gupta: Okay, so we have to be careful of the order. Okay, thank you. 300 00:35:14.400 --> 00:35:25.560 William Cheng: Right. Yeah. Yeah. So usually if you say if you call piece me attacks lock wines for me attacks. It says that you called Pisa new tax law for new tax one address me types. Why, and then 301 00:35:25.920 --> 00:35:39.030 William Cheng: So so so you could push this and then you push you know mute X number two. I just made fax number to over here. Well, then you know that when you pop them off, you will pop up new tax number two first then pop pop up let me type number one. So in that case, that should be okay. All right. 302 00:35:40.080 --> 00:35:41.400 William Cheng: They won't get out of water. 303 00:35:43.410 --> 00:35:58.830 Lalit Gupta: Yeah, no. Yeah. Another thing that I was worrying is to keep the, let's say I have some data structure like should I keep the order of three. And notice, unlock when I push it into the athlete Tina pops tech 304 00:35:59.100 --> 00:36:07.920 William Cheng: Yeah, so, so, so you need to look at your code to see if it got into any kind of trouble, right, because the example that I gave here is that you can also write your own function. 305 00:36:08.430 --> 00:36:11.760 William Cheng: Right. So inside your own function. You can also free about free up a bunch of stuff. 306 00:36:12.180 --> 00:36:21.660 William Cheng: Okay, so. So in that case, if you, you know. So again, you need to you need to understand the order. So this way you know that we know when this function get executed. You know, if you had a free a data structure. 307 00:36:21.870 --> 00:36:27.420 William Cheng: Is that data structure valid. Are you going to free a twice. You know, you gotta, you gotta, you gotta make sure you don't have bugs like that. 308 00:36:27.660 --> 00:36:36.570 William Cheng: Okay, okay. So it's the responsibility of the programmer to make sure they do the right thing. So again, the piece of library just give you the tools so that so that this can be done in the right way. 309 00:36:37.620 --> 00:36:39.690 William Cheng: They don't really enforce that it will be done in the right way. 310 00:36:40.650 --> 00:36:43.260 William Cheng: Okay. Okay. Thank you. 311 00:36:43.620 --> 00:36:43.860 Yeah. 312 00:36:55.470 --> 00:37:04.740 William Cheng: So that's why a lot of times in this class was sort of talk about the higher level principle and then you know when you try to write your own code they need to worry about these things. 313 00:37:10.500 --> 00:37:12.090 William Cheng: Any other question. 314 00:37:17.340 --> 00:37:27.660 William Cheng: Okay, so if there's no other questions. I'm going to do what I did before. I'm gonna stop the recording so you guys can talk to each other. And then if you're done. I will come back and then 315 00:37:28.020 --> 00:37:32.430 William Cheng: Check to see if there's anybody in the room, if there's nobody in the room, then I will close the lecture, okay. 316 00:37:34.110 --> 00:37:36.270 William Cheng: All right, let me stop the recording.