The 75-year-old tried to buy an expensive car and was kicked out of the show, but a surprise happened when he returned. Polished windows, lacquered floor, ironed with a white shirt and branded ties, and all this in an empty car dealership, young people were importantly loitering around the hall providing visibility of vigorous activity, visitors came infrequently, but in this case not in quantity benefit and in quality, it is clothing store wear, besides buyers, there are onlookers who would only gaze and touch, such rarely appear here, mainly if real potential buyers come in, such staff could at first glance. Determine, therefore, in the middle of a normal working day, a poorly dressed grandfather entered the car dealership with a shabby shopping bag, everyone immediately realized that he got here by accident, the manager just looked at each other, no one was in a hurry to come up with an offer of help, they thought that grandfather would look at the prices on Tuesday and understand where he got to and surrender, as usually such a contingent does. It happens that the salon is wandering around, it is not clear what comes to their minds to hope that the grocery store is hidden here, I will leave your purse with you, grandfather went to the administrator and, as if nothing had happened, turned to the girl behind the counter, the young girl raised her eyebrows and critically examined the visitor, there was nothing in him to show himself as a millionaire ready to buy an expensive car, the administrator glanced at the manager, everyone just, chuckled, watched the visitor on the side, waited for him to come to his senses and leave the salon, in other cases, seeing a potential client, they would rush to him with smiles on their faces, this kind of grandpa that no one wants to grovel in front of him, grandfather lingered for a short time near the car as if he was looking for something something definite, finally approached the most expensive car and started walking around it in circles, the manager quietly giggling among themselves, immediately. Found the most expensive car, whispered one of the guys, poverty from the same place the girl smirked, can offer him a cart from the supermarket, she giggled at her witty jokes. Come on, a man dot although he wants to look from the outside, the quietest manager began to protect the old man, they still won't by the other guy disgustedly noticed, lets you from here, the girl suggested, let the quiet guy continue to protect his grandfather, sometimes the rich go in circles and they don't buy anything, but this one the worse, you are kidding Vlad, the girl grimaced, the same dirty all you can do this is at best, but if it seems crazy and we decide to destroy everything here. I don't want to be responsible for everything. And then the grandfather opened the car door and began to look closely to get behind the wheel, the manager tensed, do something the girl demanded, you see that the administrator does not pay attention to the visitor and speaks on the phone, let him sit there, the defender replied to grandfather, let him sit on the bench, the girl frowned and ran to the guard, grandfather looked inside the cabin and examined it for a while, the car was gorgeous he had never seen such a luxury, he smiled and was about to sit behind the driver's seat when a hand lay on his shoulder, the elderly visitor turned around, stood in front of him a security guard and two managers, grandpa, secondly, unfortunately, the security guard smiled politely, why, grandfather was surprised, isn't the car here to look at and try them, the girl behind the guard barely held back a laugh, for safety, the guard calmly said the car is expensive already booked, if any misunderstanding with it happened the new owner to the court against us will give, and how can I see if grandfather started, no way now, unfortunately, we have to ask you to leave the salon, we have technical issues, grandfather was taken out of the salon, he calmly fulfilled the request of the staff and sadly walked to the bus stop, the administrator said that she didn't know how to send him out more politely, don't tell me, I have goosebumps, the manager's girlfriend supported her, I think now she'll break something for us to rake, and she, looking back at her grandfather, went deep into the salon almost stumbling over the bag which the visitor asked to leave the bag at the administrator, he forgot the bag she shouted out, it bounced off with disgust as if it were a heap of dirt, with such checkered bags, old people often, go to the market, usually they take care of this belongings for years from which the bag is washed almost to holes, although I grandfather's it was not dirty, it is clear that it was washed but very shabby, and the girl disdained to take it, and then she was completely frightened, other managers and a security guard were no longer hurrying up to her, listen, it sounds like there is something dangerous, the girl looked anxiously at the guard, stop talking nonsense, the very manager vlad, approach the bag, no one had time to say anything as he grabbed the bag and ran for grandfather, alexander igorevic, lowering his head, slowly walked to a stop, he understood that the store simply did not want to serve him, because he did not fit in such a salon in terms of status, she was dressed too poor, and he had nothing to say about protection, he really had no money for a car it was, and the price is impressive, I remember when I began to take an interest in this car, it cost less. Well, what could be expected, the price of bread went up, the communal apartment is growing, of course, and the car will cost more. Reflections were interrupted by a young man running from behind, you took the bag, a guy in a white shirt and a familiar tie was smiling, alexander igorevic realized that the young man was from the salon, and then he saw his bag, here's an old fool, grandfather hit himself on the forehead, of course he forgot, I was completely out of my head, I saw the prices and was upset, and why did you go into the salon, the guy asked cautiously, did you really want to buy, vlad did not believe that. Grandfather that was why he was in the salon, but in a sense, the young man was a romantic, he read a lot of books, I watched films, it happened in life that old people were sent like that, it turned out that they were millionaires, I'm sorry that they asked you so, but you can understand us, vlad recently from his grandfather began to explain himself for his colleagues, even if you are a millionaire but are dressed in cheap things, you will be asked, you understand that they are greeted by their clothes, yes, I'm not a millionaire, grandfather smiled sadly, retirement as everyone has been collecting cardboard bottles for a couple of years, they are slowly collecting, grandpa oh I opened the bag and showed the young man, the bags as widened, the money was neatly stacked in a bundle, mostly 501,000 bills, but the 50000s were also visible, so having almost saved up, the price for the car went up, alexander, igorevic sobbed, you have a dream, asked vlad, from my wife, an elderly man took a bag from a guy, hugged it to him and went away, wait, vlad stopped grandfather, maybe I can help with something, no son, she doesn't want another car. alexander igorevic smiled and decided that the guy wants to offer him something else and the seller is already ready to knock on anything just to buy, but he needs this particular car, otherwise there is no point in buying, no, that you are not. I'm not in that sense, vlad was embarrassed even from such an assumption, maybe I can help you solve something with a discount, I don't promise, of course, and time. it will take more. but I'm sure we will succeed, we don't have time, and alexander igorevic told the young man that his wife was dying, and two years ago she was full of strength, they made plans, they wanted to go on a trip, once katya saw this car and her eyes lit up, says, sasha, let's spit on all our lives alone, let's buy such a car in old age, we are chic, then we lived in three children, we have no children, why do we need such an apartment, katya, and I figured that if we sell our housing and buy a small apartment, there was no time for the car to fight cancer for two years, some of our savings were spent on treatment, but I still wanted to surprise my wife, started collecting cardboard bottles, while she was either at home or in the hospital, but I walked around, I know places where there are a lot of things there is, it seems that the dream of being close to chemotherapy is no longer bringing results, and she has very little left. vlad listened, there was nothing to say, only asked how much was missing, the amount named by the grandfather was clearly at a discount didn't feel like it, but he just didn't let his grandfather go, asked where he lived, came to his house in the evening, katya, the wife of alexander igorevic, was pale and was almost exhausted at home, she offered to drink tea with them, the owners went down as if everything was fine with them, the elderly spouses held each other's hands all the time, the love. between them was so strong, so unfortunately they didn't have to be together for long, when vlad left he handed alexander igorevic a bundle, this is your dream, the young man smiled, now enough for a car, and he hurried to leave, grandfather tried to stop him to give up money but the guy only asked not to tell anyone that he helped. the next day, the same grandfather came to the car dealership again, but already in a suit, it is true of the old style, but it is clear that he was trying to be at the parade, the staff tensed, they did not dare to expel the visitor, still positioned as loyal to customers while the administrator was deciding to refuse, as it were, gently, grandfather went into the salon with his bag and again approached the same car, one of the managers hurried to him, the car was reserved, he started yesterday's story again, and if i want to buy it right now, he asked alexander igorevic, the manager looked around in confusion, apparently some kind of joke, but the grandfather opened the bag in front of him, this widened his eyes, the manager immediately became friendly and began to show his grandfather all sorts of signs of attention, offered to try the car, opened the doors and told all the nuances of the technical details of this wonderful car, the rest of the staff with open arms, watched what was happening, the reason for such attention to the old man nobody except vlad i understood, only later, when my grandfather dumped packs of money, they all started staring at the manager who had such a successful client, vlad did not show that he had a helping hand, and alexander igorevic also did not say anything, but the young man was very happy for his grandfather who, after all the paperwork, left the salon in a brand new car, kathya, alexander igorevic flew into the apartment happy, let's go for a ride, an elderly woman was sitting in front of the tv today, her condition improved when he took kathya out into the street she gasped her eyes did not believe when you heard that you robbed the bank, looked at, her husband in fright, grandmother, everything is legally deer spouse, alexander igorevic opened the door for his wife and until evening they were rode around the suburbs, beloved wife's dream turned out, they could leave everything in travel, how much life was left to wait still, they were both happy, two old men who allowed themselves to enjoy life, and the next morning she left, the wife of alexander igorevic lay in bed and there was a smile on her face, grandfather did everything to the last day his beloved woman was happy, and they were together until the last they enjoyed what they dreamed of, after a while this grandfather came to the car dealership again but without a bag, he was. Already greeted warmly, each manager tried to give the visitor maximum attention, on their faces there were smiles, alexander igorevic's face was gloomy, and only Vlad understood what was happening, grandfather approached the young man and handed him the keys, thank you son, grandfather said in a trembling voice, now let it be yours. Vlad tried to hold back his tears, he did not know what to say, but only blinks often, they re-registered as a young manager who was the only one who did not remain indifferent when the grandfather was asked to leave the salon, Vlad then often drove into his grandfather in this car, distracted him with conversations, helped to survive his tragedy, alexander igorevic was glad that his wife went to heaven happy and left such a mark on her life, made a gift for a good guy, after all, the young man himself was not rich, he gave all his savings that he saved for a car to an unfamiliar old man, did not regret it, gave it to fulfill the dream of the elderly spouses, thank you all for your attention, and see you soon.


I hate to ask you to do this, but can you take this once you start the video? It's just going. Oh, it is? Yeah. Okay, great. Let's get going. Okay, so we have a lot to do today. We're going to talk about synchronization primitives. How many people are glad it's Friday? All right. The people who are not here are probably even happier it's Friday. You might be happier it's Friday if you weren't here. All right, so today we're going to try to get through locks. So we'll start off by talking about critical sections, which we sort of got into last time. And then we'll talk about two different types of locking primitive and when to use them. This is information that hopefully will be starting to line up with the work you're doing on assignment one. How many people have started assignment one? All right, good. If your hand isn't up, you have a week. All right, that's enough time. It's not going to continue to be enough time if you don't do something proactive about it. All right, so just a couple announcements. Remember next Wednesday and Friday, I won't be here. Guru will be here. Guru will be screening classic lecture videos from last year. And that's what we'll do in class. So you're also welcome to watch those online. It doesn't matter. But if you want to come, bring popcorn, we'll show them in here during the hour. Also, recitation on Friday will not happen. I'm sorry for those of you that were looking forward to getting up and getting here at 8 a.m. for the Friday morning recitation next week. Jing Hao will be with me in Santa Fe. So we will not do that. However, Tuesday's recitation like last week, like this week, will be taped. And we will post that video online. So if you normally go to recitation on Friday or if you normally don't go to recitation, the video will be available. These are all on the calendar. So trust the calendar. The calendar's always right. Assignment one is due Friday the 13th. Next Friday. It turns out, actually, I realized that we have two assignments in this class that are both due on Friday the 13th. This is the first one. Assignment two is due exactly a month later. And again, thanks to the collaboration between February and March, February having a number of days. It is divisible by seven. I don't know how many years this happens, where there are two Friday to 13th and back-to-back months. Maybe somebody can look that up for me. But anyway, that's what's going to happen. Finally, I don't know how many of you guys were able to make the event yesterday, the Scientista event. I want to...it's Kendra here. Kendra, Natasha, Gila. Apparently, the event was so great they decided not to come to class today. But some of your classmates were involved in organizing this in one of the ninjas. If you guys want to join the mailing list, this is the URL. This is really, I think, something that's really important for our entire field. Here she is. We're just talking about you. Yeah. So let's all give Gila a round of applause for the event yesterday. It was awesome. All right. And there's the URL if you want to sign up for the mailing list. I hope that's right. I just typed it up. It looks right to me. All right. Yeah, there we go. There's the assignment. There's the Friday to the 13th, man. Finish your locks the first time, or they will be back. You just don't want to mess with the Friday to the 13th assignments. Either one of them. Maybe this is before your time. I never saw these movies either, but anyway. OK, so let's talk about what we started to talk about last time. We'll just do a little bit of review. So the thing to keep in mind with synchronization, I know we've shifted things around this here, is that you have to stop making assumptions about the order in which your threads run. So what are the things that you need to keep in mind whenever you are working in a multi-threaded environment? What are some of the assumptions that I have to make? Or the assumptions that I can no longer make? Who remembers one of them? Unless you do something about it, what will threads do? What can threads do? Yeah. They can run. So essentially they can run in any order, right? They can run in any order. What else can they do that you may not want them to do? They can be stopped at any point in time. And restart it at any point in time later, right? And they may remain stopped for an arbitrary period of time. This is how we multiplex the CPU. And again, we'll come back to that in a week. But when we start thinking about synchronization, this is what we have to remember, OK? And again, normally these are things that we want to happen. But when it starts to come to synchronization, what we need are some tools that allow us to impose some control over what would normally be sort of an arbitrary collection of thread stopping and starting at random moments, right? There's times in which we need to preserve certain properties. And we'll start talking about that today. All right. A race condition is when the output of a program is unexpectedly dependent on time.  And the first time everything runs perfectly. And the second time something bad happens. Now what people have found in this course I just want to warn you is that somehow, and I don't know how we did this, but the auto grader is extremely good at finding that time that your code that has a race condition doesn't work. It may work a hundred times on your local machine. And once you upload it for grading, that'll be the time it doesn't work. I promise you. And again, I don't know how it does it. It's sort of spooky. I don't even want to look into it. I feel like the auto grader has developed some sort of intelligence of its own at this point. And so I'm not really that curious, but it's good. Because we want to find that one time. As a programmer, you want to find that one time. Maybe it doesn't happen to you.  And that customer will be mad. And again, remember that the race condition depends on what we expect it to happen. So we want a certain thing to be true. And when we start talking, so today we're going to go through some of these primitives. On Monday we will use some of the primitives we discussed today to try to solve some real synchronization problems. You guys have a few more that you're going to do as part of assignment one. And on Monday we'll go through some in class. But a lot of times when we start approaching one of these problems, the first thing we do is we decide what do we want to happen? What do we want to be true? What are the invariants that we want to preserve? And when we talked about the problem, we talked about the bank example last time. And there we knew what the answer should be. And it's just a question of ensuring that no matter how the threads are run, the correct answer is going to be the one that they're going to arrive at. And we'll go back to that example today. And fix it. So concurrency and atomicity. Concurrency is the illusion that there's a lot more going on on your system than you think there is. What is atomicity? Oh, does this still work? Sweet. Todd. Where is Todd? He got nothing. Let's try deep. Now technically someone could just be sitting here who's actually deep and not saying anything. I can't look at 100 people in that span of time. We're just going to let him off the hook. Shashank. Yeah. So atomicity is the illusion that a bunch of things that the machine actually has to do separately happen all at once. It's one big indivisible blob. And when we go back to our bank example, that's what we wanted to happen. We wanted that entire series of instructions to look atomic. Now there was a lot going on and there was a bunch of things that the machine has to do. And so we can't rely on the machine to ensure atomicity for us. We talked about things that might look atomic to you in C are not actually atomic. Just initializing a variable might require several instructions. So you can't assume that a single line of C code is even atomic. There might be other things that the machine needs to do to actually implement that. So we need ways of building atomicity despite the fact that what the machine is giving us are these very, very low level instructions. The machine has no instruction increase the balance in this account by this amount. That would be a pretty, pretty huge architecture if you needed a special hardware instruction for everything you needed to do atomic. So we need a better way of doing that. That's what we'll get to. All right. What is a critical section? I think we talked about this last time. Of course, that was two days ago. Yeah. Yeah, so critical, you're almost there. I'm going to give you points for that. A critical section is a portion of the code that we only allow one thread to be executing at any given point in time. And you can see there's a natural connection between atomicity and a critical section. Frequently the way we achieve atomicity is we put the things we want to be atomic inside a critical section. That way they look atomic to threads outside. Right. Okay. Right. I just said awesome. Okay. So when we went through this example, we identified the private state, which is this local variable that represents how much money I have. We represented, we figured out what the shared state was. And we identified that lines two to four, maybe five, depending on how much you want to irritate your customers, are inside the critical section. And this was what we started. Okay. So this is new stuff. I forgot to have a question. So the amount of questions with the stuff that we just went through before we plunge onward. I mean, the illusion of, yeah, I think it could be both. I mean, the illusion of concurrency is something that you guys experience every day. Because you think that your computer is simultaneously doing a bunch of things that it's not. I think the illusion of atomicity is probably something that we experience less when it happens and more when it does not happen. So for example, I try to add something to my shopping cart online and it adds it three times or something like that, something dumb. So you see this more when it breaks. But concurrency you see all the time. That's just, that's how you've always experienced computers. And when we come back to see if you have multiplexing, we'll talk about some changes we can make to your computer that would cause you to stop experiencing concurrency. So for, you know, if your computer always ran the same thread for like a second at a time, then your computer would be very interesting. It'd be like a second's worth of music, a second's worth of mouse movement, a second's worth of music. It's probably not how you want your computer to work. Okay. So requirements for a critical section. These are the design requirements for implementing various types of tools that allow us to create critical sections. So the first one is simple. There's only one thread inside the critical section at a time. We call this mutual exclusion. If I'm inside the critical section, I am excluding all other threads that might be trying to enter. Right? Progress. Eventually, once I'm inside the critical section, I need to be able to get out. And what that's going to allow is all of the other threads that might be waiting to enter should eventually be able to get inside and do what they need to do. Right? And finally, performance. And this is less of a design requirement for critical sections and more of a suggestion about how to use them. When we use critical sections, we normally want to keep those parts of the code as small as possible. Because what's going to happen is critical... Like we talked about, animosity and concurrency are sort of at war with each other, right? Concurrency is the machine trying to make efficient use of resources by stopping and starting things when it thinks they need to be stopped and started. The critical section is me telling the machine, you know what? The fact that you stopped a thread inside the critical section means there's several other threads that can't make any progress. Right? So these two things end up conflicting with each other. And the way that we try to preserve as much performance as possible while still ensuring correctness is making sure that the critical sections are short. Right? So in general, if you can set things up so you do a lot of stuff outside the critical section and only modify the shared state inside, that's an ideal way to do things. You guys have to experience this, right? There are some really nasty ways to get Assignment 3 to work that involve like locking around the entire virtual memory system. Right? That works. It also really stinks performance-wise. Sometimes, somehow I manage to have a filter when I'm in class and not say bad words. I don't know how that works. I hope that holds up this year, but it's been working well. All right. So how are we going to implement a critical section? There's two ways to do this. The first way is don't stop when you're inside the critical section. Once you get in there, don't stop running. Right? Again, if I stop and I don't do the other thing, then it's possible somebody else will get in. Right? So one way is as soon as I'm inside the critical section, ensure that the system will not stop me from running. The second way is don't allow other threads to enter the critical section while one's inside. If I pursue the don't enter path, I can allow myself to be stopped because other threads won't be able to get in. But if I don't have a mechanism for stopping threads from entering the critical section, I sure better not stop inside of it. Right? Now, and this is sort of, I don't know why I talk about uniprocessors anymore because even your smartphone now has like four cores. Anyway, but of historical interest for those of you that are curious about the past, at one point in time there were these things called uniprocessor machines that only had one core. And on those machines, there was this nice trick that you could do to create a critical section, which is you could simply prevent the operating system scheduler from running. If you did that, you were fine. Right? Because there was only one thing that was happening on the machine, and if you're inside the critical section and you're the thing that's happening and you prevent the operating system from stopping you, you're done. Right? On multi-core machines, this is broken. Right? Because there are fundamentally multiple things that are happening. So you might think that this is going to work. But in reality, if the operating... So I'm inside the critical section and I'm thinking, hey, I stopped the operating system scheduler from scheduling other threads, but it turns out that the operating system scheduler scheduled a thread before you stopped it that's about to get inside your critical section. Right? So this doesn't work. Right? More generally, what we really want to do is pursue the don't enter strategy. We want a way to prevent threads from getting inside of the critical section while one of... While it's in use. Right? Once a thread enters, we want to make sure that nobody else can enter as well. This is something that's much more robust and much more effective on multi-core machines. So particularly for multi-core machines, the way, you know, and this is true, we're going to find this over and over and over again. The operating system to do most of what it does relies on a really synergistic relationship with the underlying hardware. Right? There's a lot that we can do in software, but frequently it boils down to having this one thing in hardware that we need to work to help us do what we need to do. And with synchronization, the thing we rely on are these special hardware instructions that are guaranteed to be atomic or have certain properties even across multiple cores. Right? And this is something that really I need to rely on hardware to do. So let me give you a couple of examples of these. Right? The first is what's called an atomic test and set. A test and set writes a memory location and returns its old value. Right? And the idea is that the underlying hardware will ensure that this instruction is atomic with respect to other cores that are accessing the same memory location. So you can see, even if I write this out in C code, this is C pseudocode for the test and set instruction. This is not something, this is not how it works, right? Because remember, hardware has to provide this as a single atomic instruction. Right? And not only does hardware have to provide it as an atomic instruction, it has to be atomic across multiple cores that might be trying to test and set the same value. Right? So for example, if I have a memory value that has the, if I have a memory address that has the value zero and I have four cores that try to do a test and set where they change the value to one, how many cores should receive the value zero? Yeah? One. One. Only one. That's the critical part. If I did this, if I did this normally it's possible that it would actually take two hardware instructions and so it's possible that one core, two core, four cores could get the value zero. But the test and set instruction ensures that one core gets zero, every other core gets one. Right? There's something else. So this is potentially more useful. Compare and swap. So compare and swap compares the address in memory to a value that's passed in. If they are the same, then it sets a new value. Right? So you can think of it like this. I pass in a target memory address, a compare and a new value I want to set, and it succeeds only if the value is the same that the one I pass in. So same example. I've got, let's say I have four cores, core one, two, three, and four, and each core tries to compare and swap a memory address that starts off with the value zero with their core ID. So core one does one, core two does two, core three does three. Okay? What do you need to know to tell me what the value of that variable is? Now imagine they do this at the same time. As simultaneously as I can get this to happen. So how many cores receive the value zero after they do the compare and swap? All cores are going to send in zero. Right? Because that's what they're comparing against. Right? How many times will this instruction succeed? Four times? Once. Right? And what will the value of the variable be after this finish is executed? It could be one, two, three, or four, but the same core that gets back zero is going to be the core that sets the value to whatever they sent in. So if, for example, if core two gets zero back from the compare and swap, it knows that the value is two. Right? Because it won. It won the compare and swap. Right? Okay. Here we go. Link load and store conditional. So why are we talking about link load and store conditional? Does anyone know? Yeah. Load link. Sorry. Yeah. Well, I don't know about the MIPS architecture. The pseudo MIPS architecture that you guys use to do your OS 161 assignments implements this in hardware. Okay? And this is a little bit trickier. This is actually a combination of two instructions. Right? The first instruction essentially tries to, it's almost like it's trying to lock the underlying memory and then the second instruction will store a value only if the value hasn't been modified. Right? So think about it this way. The first instruction I tell the hardware, I'm about to change this memory address. But I'm going to tell you what I'm going to change it to in a minute. Right? Then when I do the store conditional, what I tell the hardware is, if that memory address has not been modified, since I told you I was going to change it just a second ago, then store this address. So think about it. The memory hardware, right, actually has to keep track of this for you. It has to know, oh, okay, there was this load link instruction that was executed a few cycles ago, and then this other core wrote to the address, so I need to tell the core that's trying to do the store conditional that this isn't okay. Right? So here is a little bit of MIPS. How many people have seen this code before? All right, how many? It's like the tiny, tiny subset. This is in your OS 161 source treat. This isn't like the machine dependent code inside the MIPS directory. Right? This is how when you guys try to use spin locks, this is the actual hardware instruction that is eventually being generated by your compiler. Right? So like I said, high-level primitives that you guys are using, like spin locks and locks and other things that you guys will build for assignment one, all come down to needing this particular set of very special machine instructions. Right? Load link, store conditional. Any questions about these? I am not going to explain GCC ASM syntax because I barely understand it myself. Right? But essentially this is a way of telling the compiler to actually output assembly code. Right? A very specific block of assembly. Right? There's, you know, this is a machine-specific feature and so there's no higher-level primitive that MIPS, that C supports that maps down to this. Right? Because not every, even not every MIPS machine has this set of instructions. I'm not even sure, so you have to keep in mind, MIPS R3000 is a really old architecture. I doubt that there were, I don't know, I shouldn't say this on camera, I doubt that there were MIPS R3000 machines that had more than one core and so I'm pretty sure that David just implemented this himself in the simulator and I don't think this is historically accurate in any way. Right? But we wanted to give you guys a multi-core simulator eventually and so we needed this sort of support. Right? So David shows he wanted to do load link, store conditional. It's kind of a cool set of instructions. All right. Any question about atomic instructions? Yeah. Yeah, yeah. So sometimes this is referred to as a test, test and set. Right? Don't remember why that is. I'll have to look it up. It's a test, test and set is a variant of test and set. Right? And I'm sure someone could find out what it means on Wikipedia and I'm sorry I can't explain it right now. Students one, Jeff's two. Okay. Any other questions? How about a question I can actually answer? No one's going to ask me. Okay. All right. So in order to allow us to build up these higher level synchronization primitives, remember the hardware has to give us this help. Right? The hardware has to provide these instructions so that we can use them. Right? Or there's, or you know, I can build, there's some hardware support for synchronization and I can build similar instructions in soft. Right? But there's always something at the end of the day where I need some help from the underlying hardware. Okay? We'll go through the aside. This is kind of cool though that some of these synchronization primitives don't scale very well. If you want to solve this problem, you can come work in my research group. There's still people working on this. And, and if you guys, so let me ask you a question.  I mean, I've got 64, right? I mean, five years from now are you going to have a 512 core processor? How many people think they will? Aren't you guys hopeful about the future? You guys were millennials. You guys supposed to be like, of course, yeah. You know, maybe you think you'll have more? I don't know. Yeah, there start to be some bottlenecks here, right? Especially with memory, right? You know, memory, particularly once you get to big core count machines, the model of memory that a lot of systems rely on is, is starts to melt down, right? So probably not going to, you probably will see some kind of machine with that many cores, but it's going to be different than the kind of machines that you're used to. It's not going to give you some of the same really nice guarantees that you're, you're normally used to. Okay. So let's go back to our bank example and let's figure out how to fix this synchronization bug. So we know we have a problem because we were able to show that there were several cases where the interleaving of the threads caused me to get different answers. What is that called? It's called a race condition. So my code before had a race condition, right? Here was the code before. And now who has a suggestion about what I should do? So I'm going to try to use a test and set to fix this problem. Yeah. Yeah. So I essentially want to use a test and set to establish a critical section around the part of the code that I need to be atomic. All right? So here we go. I create my variable that the test and set is going to modify and then I'm done, right? How many people think this works? What's wrong with it? I think this looks awesome. First, it's even like color coded a little bit too. I have no idea how the syntax highlighter works. It's clearly kind of strange. What's wrong with this? So again, I set the test and set at the top from 0 to 1 and then at the bottom I clear it. Why won't this work? Will this work? There's nothing to do with scope. Yeah. What am I doing with the output from the test and set? Remember, the test and set is going to test at the variables a certain thing and return the old value, right? But if I don't use the old value, does this code change the operation of this function at all? No, right? I mean, I clearly need to do something if there's another thread that's already inside the critical section. Okay? Yeah, so how do I tell? I need to consume the output of the test and set. Okay, so let's try this again. So I put in my if block at the top. So what does it mean that the test and set is 1? What does that indicate? That there's another thread inside the critical section, right? I initialize the test and set to 0 when I started and so the only way it's 1 is if somebody is between this called the test and set and this called the test and set, which is where I've established my critical section. So I know there's another thread inside of it if this returns 1. But then, what do I do? Wait, like that. Well, there's a couple of problems, right? So I mean, I need to wait until the value is what? 0. So let's try this again. Now, so now I have a while loop here and here's what I'm going to do. When I get to the top of the loop, I'm going to test the test and set. If the test and set is 1, I'm going to test it again and I'm going to continue to do this until what's going to break me out of this loop? When it finally turns to 0. So does this work? How many people think this works? Yeah, this works. How many people think this is a good idea? So what's the problem with this? So let's say there's a thread inside the critical section and another thread, maybe it's running on the same core because the thread that was inside the critical section was stopped. Threads can be stopped and started at any time or maybe that thread was running on another core. It hits the top of that critical section and it just sits there waiting. But it's waiting by executing instructions. So we call this busy wait. So here's what would happen. Again, go back to the example.  He hits the top of the test and set he's fine. He goes right through because the test and set is 0. This guy gets there, he hits the test and set and he hits the test and set and he hits the test and set and he just keeps doing this. So the B student is actively waiting. Again, we refer to this as busy waiting. It's waiting that is consuming cycles on the process. And yeah, this is not good, especially when you guys are trying to earn your grades at the class. Eventually someone has to win. So the problems with this approach are the one we've identified. We don't want to busy waiting. And it turns out busy waiting on these... So it's worse than you think because these hardware instructions that are used to implement critical sections like the atomic test and set or load, load and... leak, load and store conditional are actually frequently pretty heavyweight instructions for the hardware to execute. They require coordination potentially between the cores. So these instructions are not only... It's not only bad to just sit there doing nothing with the processor, making no progress, accomplishing very little, but these instructions are also frequently not ones you want to execute overnight. And on a multi-core system, this could be bad. And we'll talk about trade-offs with busy and sleep waiting in a minute. But on a single-core system, this is really bad. Because on a single-core system, keep in mind, while I'm using the processor, nothing else is going to happen. So if thread... If the B-student is sitting there whacking on the door, all he's doing is consuming CPU cycles that the other student needs to make forward progress. So this is really, really bad on a single-core system. But again, who cares? We don't have those anymore, so it doesn't matter. So what we've implemented today is a lock. A lock is a synchronization primitive that is primarily used to create and protect critical sections of code. There are other uses for locks, but this is the one that we're going to start with. So when I acquire a critical section, I acquire the lock. When I leave the critical section, I drop the lock. And what we've built today is a spin lock. It's a lock that guards a critical section, and spin describes the process of acquiring. Typically, when you talk about locks and see lock implementations, a lock without a prefix refers to a lock that does not typically spin. A spin lock is used to describe a lock that will actually busy wait for the resource. And there are reasons to use spin locks. We will get to those in a second. But again, if you hear about something that's a lock, you can probably rely on the fact that that's actually going to stop the thread from running while it's waiting, and we'll show how that happens in a second. It's unlikely that you will need a spin lock to solve a synchronization problem. There are places where you can use spin locks, and we'll talk about the trade-off between spinning and sleeping in a minute. They're frequently used to build higher-level synchronization programs. So if you guys have examined the semaphore implementation, you'll see that the semaphore implementation uses a spin lock to safely bridge to the wait channel. So the wait channel bridging is designed to ensure that the condition that I'm about to go to sleep on doesn't change between the time I start to wait and the time that I actually arrive at the wait queue. If that happened, I might end up waiting forever, which would not be good. All right, so let's go back to this, and voila, here's what we have. We have a lock.  I call lock release at the bottom, right? And this is a cleaner way of doing this lock acquire. The semantics of lock acquire are that when it returns, I hold the lock. What it does until it returns is its problem, right? But when it returns, I hold the lock, so I don't need to introduce any extra conditionals into my code. Any questions about this before we go on? Okay, so what happens if we call... So now that we sort of abstracted away the details of the lock, what happens if we call lock acquire when there's somebody else inside the critical section, aka somebody else has acquired and is holding the lock? What does it do? It has to wait until the other thread calls lock release, right? And then, so if I call lock acquire and another thread calls lock release, this would be a great short answer exam question that I'm giving away right now, right? I could have put this one away in my back pocket and used it on the midterm, so it will do the true, false in class anyway. If I call lock acquire and another thread calls lock release, then I acquire the lock, true or false? True or false questions are too easy, right? False, why not? What else could have happened? Could be somebody else waiting, right? When a thread holding a lock calls lock release, it means that some thread that has tried to call lock acquire, if there are threads waiting, one of them will make forward progress. If there's not, then the next thread that calls lock acquire Okay, so how do we wait for the lock to become available, right? The first thing that we presented is this active waiting strategy, right? So I literally repeat some action until the lock becomes available. The action I was repeating was this underlined atomic instruction provided by Harper, okay? The other approach is passive waiting or sleeping, okay? And this requires more help, right? This requires the operating system or, you know, the thread library or whatever to provide me with a little bit more help doing this, right? So essentially, the way you can think about passive waiting is when I go to sleep on the lock, when I try to acquire lock and the lock is held, I tell the operating system, I am waiting for X to happen. And when it happens, please let me run again. And the operating system says, fine. Sounds good. Go to sleep. When another thread calls lock release, the operating system looks for all the threads that are waiting on that particular thing to happen, and it wakes them up. All of them, right? Now, it wakes up all of them. One of them is potentially going to be able to acquire the lock again, and then we repeat this process, right? So again, this requires a little bit more support. Now, there are cases when spin locks are actually an appropriate primitive to use, right? Yeah? Yeah, sure. Ah, okay. So everyone, someone usually asks this on piazza, but I'm glad someone asked it in class. So let's say I have 10 threads that are waiting on a particular lock to be released, and the lock is released. How many threads should I wake up? First one in the queue? That's interesting. So when I took this class, I thought I was all clever, and that's what I did with my locks. I was like, these locks are dumb. I'm going to build a better one, right? And so I built this extra function. At the time, there was no way to just wake up one thing that was waiting on a wait channel. Now, David has that feature. I'm sure he copied my code for that. Anyway, so the point is, I thought this was a great idea. I'll just wake up one thread, right? So it turns out, and we'll come back to this when we talk about thread scheduling, usually I don't just want to wake up one thread. Because the code, so which thread runs is really not the lock's decision to make, right? Maybe I have 10 threads sleeping on that lock, but one of them is really important, and the other ones aren't. Usually, the lock application has no idea what's important and what's not. So what it does to be safe is it wakes them all up, and then it lets the thread scheduler decide what to do. And again, we'll come back to scheduling in a week or two when we talk about policies that we applied to how to abstract the CP, right? But again, it seems counterintuitive. It seems it would be like a lot better to just wake up one. But the problem is I'm trying to separate things out. I want the scheduler to make decisions about what to run, and the lock implementation just implements a lock, right? So when I wake up things from a lock, I normally wake up everybody, right? And I just say, hey, scheduler, you figure out what to do next, yeah. Yeah, so that's a great question. What's your space so it end up, you'd be right, because as soon as I wake up a thread, the operating system can schedule it, right? What's happening here is I am the operating system, right? So I'm thinking about it from that perspective. And while I'm waking up the thread, I'm running, right? So nothing else can really run, right? So essentially, I can mark, it's a great question. I can mark a bunch of threads as being ready to run, okay? They end up in a queue of threads that's then chosen by the scheduler the next time there's a scheduling decision to make, right? Does that make sense? Great question. Any other questions? Okay. And again, remember, only on a multi-core system do I ever want to spin, because on a single-core system I'm just blocking another thread that is going to change the thing that I'm waiting for, okay? But the main reason to spin in a critical section is because if a critical section is very short, okay? And what we're doing here when we decide whether to spin or sleep is we're balancing two overheads, okay? The first overhead is the overhead of spinning, because again, when I'm spinning, I'm wasting time. I'm wasting CPU cycles that somebody else could use, okay? So this is overhead to repeatedly trying to see if something has happened that I'm waiting for. On the other hand, and again, unfortunately, this is a consequence of putting this material before threads rather than after, there is an overhead to stop a thread from running and start another thread. We call that process a context switch and we will talk about it next week or the week after. So there's these two overheads here. This is overhead to stopping one thread and starting another, which is what I'm going to do if I sleep. And there's the overhead of repeatedly doing the same thing over and over again and hoping that something different is going to happen, and that's the overhead if I spin, right? So here's an example if the critical section is short, but I choose to sleep, right? So thread one acquired the lock, but the critical section was very small, all right? Sorry. Every year, new bugs on the slides. Thread two, the red thread, we'll just call them red and green, right? Red thread had to try to acquire the lock while thread one was in the critical section and it shows to go to sleep, okay? And so there's this whole process that the processor has to perform in order to put it to sleep and then later to wake it up again, right? And by the time it wakes up, thread one is long gone. Sorry, the green thread is long gone. It's actually the critical section a long time ago. So here it would have been a better idea to spin, right? Because I would have acquired the lock right here, right? And the amount of time I wasted spinning would actually be smaller the amount of time it took the system to put me to sleep and wake me up again later, okay? If the critical section is long and I spin, then I might end up wasting more time than the context which would have taken. So here's an example where the red thread acquires the lock and actually this lock needs to be held for quite a bit of time. Maybe the thread actually has to be able to sleep with the lock. It's going to do some I-O. It's like waiting for tomorrow to happen or something. Who knows, right? And in the meantime, thread two, sorry, the red thread is constantly just sitting there, are you done yet? Are you done yet? Are you done yet? Right? I mean, and that's just wasting lots of CPU cycles. Okay? Do you guys understand this trade-off? It's pretty cool. All right. So sleeping, if you guys have looked at weight channels, you guys have seen this happen. You can sort of map from weight channels to thread sleep. When I sleep, again, I sleep on a key. I tell the operating system, wake me up when this thing happens. And when I wake, I pass a key and I allow the operating system to wake up all the other threads that are asleep. How many people have looked at weight channels already? Did Jing Hao do that in recitation? Okay. Well, you guys will see them soon if you have. And weight channels implement this piece of function now. Essentially, right? It's, you know, weight, W Chan sleep. Is that the name of it? This is what it was called when I took the class for real. I'm not kidding. So this is what I remember. W Chan sleep, W Chan wake one, W Chan wake all. I mean, it's essentially this, right? Okay. All right, fine.  Or maybe we'll get stuck here. We'll have to come back. So remember when we started talking about synchronization, there were a couple of things. Well, actually, sorry, let me slow down. Are there any questions about locks? Yeah. What's that? I suspect, yeah, I suspect that spin locks were probably, you know, accompanied the first multi-core systems. But remember, I mean, multi-core systems have existed for a long time, right? Multi-core systems being so ubiquitous that there are a few single-core systems left is much more modern, right? I mean, we've had multi-core systems for, I had, my brother had a roommate when he was in college who had purchased a, and this was, I don't know, he probably went to, started college in 2002, 2001. So his roommate had this really big, expensive computer that his parents had bought him for college. And it actually was a multi-core, it was a multi-processor machine, right? It had like two sockets and everything, man. Those things were awesome. And the thing that was cool was that Dell, well, I shouldn't impugn any particular computer company, right? Some computer company, right? Like Smompac or whatever, I don't know. Had sold him this computer with Windows 98 on it. So, can anyone identify the problem here? Yeah. Yeah, no multi-processor supported good old Windows 98, right? So he had this big expensive computer that was probably three times as expensive as it would have been because it had two processors. And one of them wasn't even being turned on, right? They were being initialized. They were just sitting there, right? Like, maybe it was the backup processor. It was like, I'll fail over to that one later when the first one burns out, right? He was pretty bummed about that. So anyway, he, what's that? That's fair processor. Yeah, exactly. It's like raid with my processors. No, I don't want to do that. Processors don't break, right? So anyway, but yeah, I mean, I think that spin locks probably existed for a long, long time, right? The ubiquity of multi-core is pretty cool. And that's kind of what has driven us to need to use those all the time. Good question. Any other questions about locks? All right. So remember when we talked about synchronization, we talked about correctness? We also talked about communication, allowing threads that are working on a project together, doing some type of, you know, both sort of communicating, working on something to safely communicate. And on Monday, we'll talk about a classic problem where this is the case.  Some of them are putting items into a queue of items that need to be worked on, and other ones are taking items out of that queue and working on them. I don't know why. You feel like, you know, when you do produce or consumer, you always feel like the buffer is the middleman, right? It's like the office space movie, right? I take the specifications from the customers to the engineers, right? Why can the customers do that themselves? Anyway, so we'll talk about a bounded producer-consumer, but any, but you know, producers, items in the buffer, consumers are taking them out of the buffer, right? So there's a case where I have multiple threads, the consumer threads and the producer threads, and they need to communicate with each other about the state of the buffer. Are there items in the buffer? Is the buffer full? What needs to happen, okay? So while locks are designed to protect critical sections, you can sort of think of locks as a signaling mechanism, although I don't want to really push this because it's, but it's so limited, right? Lock release essentially tells all the threads that have called lock acquire, hey, the critical section can now be entered, okay? But there's other types of signals that I might want to deliver, right? Things like the buffer that we're sharing has some data in it that you need to process, or your child has exited, right? This is a big hint for assignment two. And in order to do that, one of the synchronization primitives we've given you guys to work on for assignment one is called condition variables, okay? And a condition variable is a synchronized signaling mechanism, okay? It allows me to do a couple of things. The first thing is wait for some condition to change, okay? Now condition variables have no idea what the condition is. It's up to you to check the condition and use condition variables appropriately. I think people get a little confused about the name. They're like, what's the condition? The condition variable doesn't have any idea, right? It's really just a signaling mechanism. CB Wait says I am waiting for this condition to change, potentially to become true or false or whatever, but I want the outbreak system to tell me when should I reexamine the condition? And then there are two signaling mechanisms that I can use to indicate that the condition has changed. There's usually something called CB Notify which might only wake up one thread, and there's also something called Broadcast which makes up everybody. And in the case of condition variables, this is okay. There are times, and we'll come back to this when we do our example on Monday, where I really have enough information about how the condition has changed that I know that I only want to wake up one thread. And there are other times when I don't have enough information about how the condition has changed that I want to be safe and let everybody who was waiting on a condition know that it has changed. Now, the condition is usually represented as some sort of change to shared state that's controlling how the threads execute. So in the producer-consumer buffer problem, the shared state is how many items are in the buffer. If the buffer is full, the producers have to stop producing. If the buffer is empty, the consumers have to wait before they continue to work. So the condition of the buffer affects how the threads behave and what the threads do also affects the condition. So if the producers put items into a buffer that was empty, now the consumers can work. If the consumers finish, if the consumers take an item out of a buffer that was full, now the producers have more space and they can put another item into the buffer. We'll go through this all in one. And, yeah, so, and condition variables are just a much richer way of expressing information about how the world has changed, right? And I just talked about this, right? Okay. And, yes, we will go through this, like, this example. We'll come back to Hunch, right? So why don't we stop here? We'll pick up condition variables again on Monday and then we'll do a couple of examples. So have a great weekend. Work on assignment one.


Itamar Rabinovich was Israel's negotiator with Syria, among many of his other accomplishments. He was ambassador to the United States, which was not about accomplishment either. He's been a teacher, head of Tel Aviv University. He's vice chairman of the Institute for National Security Studies in Tel Aviv, among many other things.  Israel has a new government, but a new set of relationships here. So over to you, please. Thank you. I will begin with the new Israeli government and then talk more broadly about the region. Two years ago was a very optimistic time in Arab-Israel relations. The Abraham Accords were signed. It was seen as a milestone, secondly, in Israel for the first time, an Arab party and Muslim Brotherhood, the softer version of the Muslim Brotherhood, joined the coalition. First time that an Arab party in Israel was part of a government coalition. And it seems that Arab-Israel relations were looking up. Nowadays, the perspective is far darker. The Abraham Accords are there. They did not develop into a larger regional structure. Summit of the Negev was mentioned. Some people thought that this would be the core of a Sunni-Israeli coalition against Iran and its Shiite Axis. It doesn't seem to be the case. The Abraham Accords are limited to actually very positive development in bilateral relations with the Emirates, with Bahrain, and with Morocco. Sudan is not so important in this context, but it's not the nucleus of any regional structure. In Israel itself, a good government that represented the gamut of Israeli politics all the way from the left to moderate right, and including an Arab party, collapsed after a year and a half. And not just the right wing, but the extreme right wing won the last elections. And it's probably going to form a very nationalistic government with probably negative implications for Israeli politics, Israeli society, Arab-Jewish relations inside Israel, and Israeli-Arab relations, Israeli-Palestinian relations in general. It is important to bear in mind that the elections were decided by very few votes. Actually, there was a plurality for the center-left block in the popular vote. But Netanyahu is a very good politician, election strategist. He put the right wing together in a very cohesive way. They did not lose a single vote. Center-left lost quite a few votes. And the result is that we have this perishing change in Israeli politics. Will it hold? I doubt it. I think that this government is likely to implode. The policies that the two extremist right wing parties and the ultra-orthodox parties are trying to impose on the country will lead either to implosion or to massive popular protests. I doubt that this will remain the case for very long. But we are in, I think, for a difficulty year in Israeli politics, Israeli-Arab relations inside Israel and the Israeli-Palestinian problem in a broader way. Now, let's remember one thing. Netanyahu is on trial. He's being tried for serious criminal charges, corruption, breach of faith. And what interests him the most is his own legal situation. He depends on these partners in order to be in power. He remembers that when Prime Minister Olmert left the government, he went to jail. He doesn't want to go to jail. And he wants to be in control, and he wants to reshape the legal system. This is what drives him in the first place. Let me now move more broadly to the region. And I would use the word flux. I think the region is in flux. On all three levels of politics, domestic, regional, and international. Domestic, six failed states in the region. Other countries on the eve of elections as in Turkey, in thermal, like Iran, and so forth. Originally, there is no structure. There used to be a structure. The last time we had a structure was during the Syrian Civil War and the Arab Spring when people spoke about the Saudi axis of Sunni states versus the Iranian axis. This is no longer true. There is no axis. What is very significant in regional politics is that the region has been joined by two large, powerful states, Iran and Turkey. They were not part of Middle Eastern politics most of the previous century. Only after the Iranian Revolution of 79 did Iran join Middle Eastern politics in Turkey with the first years of this century when Erdogan realized that Turkey was not going to be accepted into the European Union and he was looking for influence elsewhere, what is known as neo-automanism. So we have two countries of about 100 million people with strong economies, highly developed civil societies, strong militaries that punch at their weight in the region. What is more recent and very interesting is that these two countries are now trying to play a larger global role. Turkey has been active all the way from Azerbaijan to Libya, in East Africa, in Yemen. And Iran now, of course, joined Russia very closely and became part of the war in Ukraine. So this is not something that we were used to. We were used to larger international powers coming to the Middle East to control the Middle East. Suddenly we see Middle Eastern countries trying to play a larger role. One point you asked Mona about where is Egypt. I think there's been a shift in the Arab world from the traditional centers of Arab nationalism in Egypt, in Iraq and Syria. Egypt is sort of unto itself, Iraq and Syria in basically two failed states. And I think the focus is shifting to this part of the Arab world in the Gulf where you have stable, wealthy, highly developed countries that are now playing a much more important role in the larger Arab world. Internationally, Russia will have to see what the implications of the war in Ukraine are for its position in Syria and its ability to be effectively active in the Middle East. And the U.S. always raises the familiar question, is the U.S. pivoting away or is it not? In fact, a number of U.S. troops in the region has not declined, but the message is not very clear. And the U.S. has, I think, a hard time of finding a solution to what Minister Gargash presented eloquently yesterday. That is to say the tendency of Middle Eastern countries to say, yes, basically we are pro-Western, but we allow ourselves sort of a polygamy that you, Washington, needs to be able to live with. Thank you. Can I bring you just back into the Israeli interior for a second, just with one question? The great experiment of the previous government, which was Israeli Arabs or Israeli Palestinians, whichever you choose to say, getting involved with an Israeli government, is that experiment over or do you think it could come back again? No, it's not over. The Arab minority in Israel is 20, going up to 21, 22%. And the majority and the minority will need to find a long-term way of living with one another. Now, inside the Israeli minority, there are two contradictory trends. You see a growing middle class, a growing professional class. In my own university, Tel Aviv University, the number of Arab students rose from 4% to 16%. In the Technion in Haifa, which is Israel's MIT, it is 37% Arab students in the student population. So you see a trend of younger people moving up, becoming professional, moving to leaving their towns and settling in Tel Aviv and Haifa, and seeking integration. This is what Mahmoud Abbas and his participation in the coalition, in a way, represented. But there is a hard core of people who still oppose the very essence of the state. This will continue. It needs to be addressed by an Israeli government that will come to the Arab minority and say, listen, this is a Jewish state, but you are a significant minority of 20%. We need to find a definition of the relationship. Say cultural minority. But obviously, this is not the government that will do that in the coming year. And of course, it would help if there finally were a settlement and two states, because then people could decide where they really belonged. But we don't have to get into that right now. Our last.


Welcome back and thank you for staying with us on Y254 if you're just joining us tonight we're talking about goal setting and we've discussed quite a lot of things we've talked about the impact of goal setting we've also tried to look at how do we get to balance Lea has mentioned how she's been able to balance goals like through all the aspects that she has to set goals in her life talk to us across social media platforms at Y254 channel you can also reach me at Patricia Murioki so John let me bring you on on the part where balancing every goal that you set because as Lea said sorry sometimes you notice that your educational goals are going so well your business goals are going so well but these are part these are disconnect when it comes to everything that you wanted to achieve holistically so how do you create that balance well I think one it's important to always have a point where you get to review whatever you do because I always believe that enough times you know we are quick to set goals and at times you get too busy trying to actually achieve these goals to a next time to where we don't have even time to review so I always believe that it's very important for you to set time to have a review of these goals that you've set as a matter of fact I think to a great extent also most people fear failure and we fail to want to embrace whatever it is that we have been able to encounter to an extent where we shy away from having to deal with the reality at hand I think I'm inspired by this guy by me in the late Nelson Mandela who by the time he was you know about that he had written a book and in this book he was talking about the courage to face oneself you know because most of the times you find people are not quick enough to even create time to face themselves to be able to have a review of who they are or whatever they are doing and I think for me it's also important because life has a way of you know bringing about different results so their times you'll be successful in what you do their times you'll be failing in what you do so I think you need to have a review of the same and most still also I just so get to set this code that you're setting it's also very important for you to also be a bit practical you know in terms of the thing that you're trying to achieve because I always say that I remember at one point some time back you know we were fairly young and we were being asked so what do you want to do in another like five years you know and back then we were still early in our 20s and one guy said that he wanted to have a child in class 4 you know other particular time and he got me thinking that this guy was not married he didn't have a kid so you'd imagine within five years having a kid in class 4 not unless it's adoption or whatever if it's through the due process you know so it's good to be realistic in whatever you do we can talk about goals without talking about being specific with your goals it's supposed to be measurable goals they're supposed to be actionable they're supposed to look at time so I'd like to bring you in on these one layer how are we able to make sure that we're set in realistic goals because I believe people out here set goals but the moment you try to listen to the goals that someone has said you even wonder is a timeline that you've given to them is it enough for you to be able to get to that point so how do we set realistic goals and you can set realistic goals is by picking on like one big goal in your area in the in your area of focus like for example if I want to lose is it say 10 kilograms in the year 2020 2021 2021 sorry I beg your pardon in the year 2021 so if I want to lose 10 kgs is that realistic how what you need to have to make it realistic is have what we call a god a god roadmap a roadmap will give you step-by-step for me to achieve myself losing 10 kgs within a short time say even if it's within six months what are the things that I need to do I need to eat healthy you need to know for them to for your goal to be realistic you need to know the steps you need to take so you to get from point A to B am I going to eat healthy am I going to exercise am I going to be more careful with my mind I'm going to be my mindful of what is it that I allow to get into my brain yes so for it to be a realistic also you have to check your timeline you also have to check in terms of what is it that I need to do to get there but also in the process of being realistic we can at times limit ourselves okay sometimes I like it when especially young people take big audacious goals because you know like they say you know you could land in that in the stars don't be afraid to dream big yeah it's just that give it a time you might say I want to earn a million a month give yourself time even if you it's going to be a long-term goal okay and then you begin having realistic steps to get there do I need to go back to school to get most killed when what is what are the steps that I need to take for me to get to my big audacious you know dream all right yeah so we can't talk about goal-setting without talking about what attitude do you bring when you sit down and say at the end of this year want to buy a car what attitude as you go out there to look for the money as you go out there to look for whatever it is resource that you need to achieve a certain goal you can't do that without embracing a positive attitude so how do we do that John how do I how do people now adopt maintaining a very positive attitude throughout this process yes so now I want to put something there so answer or get to respond to that I say that where we're looking at also setting goals one of the end games you want to seek is to be successful and one thing I've learned about success success has deals that you have to pay yeah you know and if people have that at the bottom of their heart it means that you know that is actually in itself a driving force because in whichever line you are seeking to become successful there are those requirements that are that are you know set for you to get to achieve that are set for you to get to conquer so it means that in your mind you have to have this mindset you know when you talk about attitude I also think so much about the mindset that you have that whatever you seek to do for you you're not trying you know you are you're actually seeking to get to see the end of it in a bigger way so one thing I always say and I'll also actually echo what has actually been mentioned is that even in your setting of goals make these goals to actually also be bold because as a matter of fact it takes the same amount of energy rather it takes the same amount of energy to make or to have small goals as well as big goals so why do you have to actually lose your energy on small goals you know yeah so that kind of thinking is very important actually when you talk about boldness you're also talking about big you know and big does not mean that you're also not realistic yeah as a matter of fact I think in this dreaming that we have even the people who dream at night and those who dream during daytime both of them they end up dreaming you know so at I know by and large if you actually trying to think in this in this particular line you'll find that the driving force in regards to what you want to seek to achieve will be what will actually be pushing you I always try to relate goal-setting to this aspect that number one the best time to plant a tree was 25 years ago and that simply means there's some of us who in our life right now we say I wish I did whatever I was supposed to have done 25 years ago or a long time ago because I would have been in this particular place but also say where this attitude is concerned the second best time to plant a tree it is now okay as you come to as you wind up on this discussion tonight layer accountability do I need an accountability partner or how can I also be accountable by myself in the goals that I have set for myself it's very important for you to have an accountability partner actually this one from my personal experience is that I've been able to achieve more of my goals when I have an accountability partner you know these days you're not limited by boundaries my accountability partner is all the way in Malawi and we leave each other voice notes this week this is my goal and we keep each other accountable we started shows my business accountability partner and as we kept growing we have developed a friendship that now we are even keeping each other accountable when it comes to our health so we call each other what is what you know what milestones you want to hit this week and we keep each other accountable we are each other cheerleaders so it's very important for you to look for an accountability partner it doesn't have to be your family member but it has to be somebody you can trust with you because this goals are what I'm going to make you become whoever you want to become it has to be somebody you can trust with these goals somebody who can cheer you on somebody who can look in the air and tell you you know now you're really messing up yeah and somebody who is going to work with you celebrate with you the wins once you have achieved this goal so it's very key don't be afraid to try reach out to somebody who you feel you're aligned in terms of goals it can be even people who are trying to achieve other things but this is somebody you know who's going to be consistent it's going to be in your corner when you're doing this then your corner and they are going to support you and you should also offer the same to them because a relationship is more beneficial when it's mutual yeah yeah so that you're not becoming a situation and it has worked so well in fact like when you're doing something you can actually cross-tech with them and then they give you ideas critique it you know like we all I tell each other you know me I'm looking at it with a critical eye it's good but just know that I'm looking at it with a critical eye and we don't take offense because you know it is for a better man so get partner if the relationship does not work move on to the next one until you find the right one you know like in Kenya I know we have these groups sister you know when you see something those people when they see an opportunity for you they'll tell you come here come and come here this is where the opportunity is and accountability works very well because sometimes you can feel you're alone in this journey of trying especially when you're going for big dreams it's a lonely journey so you need someone to work with you the journey okay yes John for young people watching us tonight when it comes to focus like literally being able to focus on every goal and every dream and everything that you said for yourself it doesn't matter in what area or what aspect of your life how do they maintain their focus 30 seconds yes so I think where we're looking at focus it's important to actually narrow down in whatever you seek to achieve and that means there could be so many things that probably may have said to do but if you can actually get to narrow down to whatever you want to achieve I can see when that one big thing that you want to seek to do because that one big thing could also have other things that could also be attached to it so narrow down to that one big thing that you want to do then from there you cannot be able to build because if you're able to achieve one major you know thing and you have that is a big win of course you're so able to come and build from that and then of course with this with the other wins you'll be able now to get to conquer and conquer more you know so get to narrow down from there with that win get to build on that like that like that and of course you'll be able to have that focus because otherwise if you're distracted if you're chasing a lot of things I always say a person going after an elephant does not go throwing stones to bats you know so get to focus on the elephant stop wasting your energy and time throwing stones to the bats that are along the way in your journey of life yes one thing that if I'm sitting someone watching us tonight and they are now like I think I need to set goals and the salmon of land what should they consider before they set those goals you just have to know your purpose because once you know what your purpose is then you start aligning your goals towards your purpose yes so as you said you set your goals you know what your purpose is how can you know your purpose is it's a process you cannot know it in one day and remember you are an evolving being okay and sometimes you might think this is my purpose then you achieve it and God shows you yeah something new to try yeah just keep grinding keep on your grind that's what I can see okay when you fall get up fall down 10 times okay wake up 11 times okay yes thank you very much for finding the time to be here with us tonight I hope that if you if you were watching us tonight this has been a very informative discussion I also have taken one or two points home and I hope that as we said goes year 2021 we're going to be setting realistic goals and goals that we know that we are able to attain so thank you very much for being with us next week same time we're going to be diving onto career goals because today we didn't touch anything on career goals so next week you talk about career goals thank you very much my name is Patricia Morioki have a very good night