Team one do we have a name here? This is Neemak, right? I mean how would we know if it wasn't for the shirts? Neemak All right, and over here. We have the very patient very patient, but no consistency with shirts Who are you? We go on Bless your heart. Okay. Bless your heart Wigwam is Bob or is it Bob? Holy cats you've got the top dog here to keep an eye on you. I like that All right. Well, this is a unique situation as was mentioned earlier We had a little you know mix up in the how everything works here But the positive is we got four good teams Three questions each and this is going to ultimately conclude with a championship round where someone's going to win $500 Oh Are we doing up there pretty good pretty good Questions are ready. All right, let's put them up on the screen Before we get he's gonna put that up there before we get started. Could you please introduce your team? Bob Rasmussen, Janet Yonker, Jake Murray, Margaret and Tom Newhart All right, let's hear it for Wigwam. These people know how to make socks. Let me tell you a good sock outstanding And over here knee-mack looking very sharp. I don't think you're sock makers. Are you know and your name is? Stephanie, please introduce your team Vicki Chris and Linda all working at knee-mack. Yes, very nice. Well, nice job What's going on lots going on at knee-mack? Oh, yeah, how many employees at knee-mack? 1400 1400 employees and they had to boil that down to their top four players So this is going to be good. All right. We're ready to roll. Let's do this now with the two team leaders. Please come forward Stephanie Bobby, it's okay to shake hands Let's keep this Go one hand behind the back one of the table. Here we go One hundred or so county residents were surveyed name something people keep in their cars Neemax is a blanket. It's a blanket up there team one Sorry wrong. No blanket, which I think is surprising. I've got one in my car. You too. Yeah, I can't believe that Bob is it Bob 100 County residents were surveyed name something people keep in their cars Window scraper we all have Nice job wake warm Hires nothing but the best employees right Bob. That's right. Would you like to play or pass? They're gonna pass. Well, maybe I was wrong All right, we're just having fun here. All right, here we go now. How are you doing? I'm good You heard the question 100 County residents so a to z we're surveyed name something people keep in their cars a map a map do we have a map in there? Like a very good answer to me Same spelling as my wife Chris With a K, isn't it? All right. Is it really Christine? It's Christina. Christina. It's very nice Christina name something people keep in their cars Shovel a shovel a shovel a shovel that they keep a shovel in the car push shovel How you doing Linda? You look bad. You're red today Name something people keep in their cars jumper cables jumper cables gotta be Excellent back to Stephanie our fearless leader so today You guys must have done pretty well Name something people keep in their cars Flashlights Got a flashlight up there. It's your only one strike four answers on the board. Could you turn that name take for me? I like to know who I'm talking to I thank you. Hi. I'm Adam Name something people keep in their cars boots boots next repair of boots Good, Wisconsin answer though. You're down to two strikes Chris if you're gonna keep this alive You got to get this hundred County residents named something people keep in their cars Well, I'm not sure about everybody else, but I have to have Kleenex in my car Kleenex Absolutely, how about a little Kleenex? Kleenex up Nicely done Linda 100 County residents were asked People keep in their cars gloves gloves sounds like a good answer our gloves up there Chance to steal for wick-wong mills. I don't see socks up there Wait, that's a good idea. I didn't think I'd be up there. I shouldn't have even said it would occur to me I team leader. Can you mind going around here? What you think All right, could you turn your name tag to? Jeez, all right Everyone conferred you're feeling good about this for the steel name something people keep in their cars Sunglasses sunglasses show me the sunglasses for the steel show me up Team to we want gets the points number four and number two 62 to zero it's close we're question two of three lots of time with the two And Janet here we go question number two 100 teenagers were surveyed Name the best place for pizza in Sheboygan County firehouse pizza. She says Team one That is incorrect. Wow. She said it was such a certiveness Well, you've got a chance to take this and possibly player pass What do you want to do here name the best place for pizza in Sheboygan County as responded to by teenagers? Papa John's we got a little Papa John's up there. I'm sorry Isn't that delay anti-climatic for you?   I'm doing fine. No one's got an answer up there. Let me repeat the question for you 100 teens were surveyed or thereabouts Name the best place for pizza in Sheboygan County Pizza Hut Pizza Hut Pizza Hut. Yes, you're right I hardly got that out of my mouth. Well done up there. Yes Pizza Hut. So would you like to play or would you like to pass? Because these two didn't get a shot at this team if they get it right it's player pass see this see that up there It's correct player pass want to pass boy you wigwam folks are a little Given all right. All right. Here we go. Here we go now who was up here last It's jakes turn how you doing jakes pretty good. How are you? You look fantastic look great, too. Well, thanks 100 teens were surveyed name the best place for pizza in Sheboygan County Theos theos how about some pizza at theos What do you do at wigwam product development so you like create the socks you invent the socks Yes, with a skilled team of knitters Pressive. Yes. All right. Well, nice to meet you as well named the best place for pizza in Sheboygan County I'm gonna go phase phase phase pizza. Got some phase pizza up there Very good answer Margaret How you doing Tom? I'm getting acclimated. Absolutely. I met Tom at a rotary meeting about six months ago So and what wasn't it Florida? You were from or more southern northern, California northern, California Welcome to Wisconsin Tom named the best place for pizza in Sheboygan County Toppers toppers toppers up there Team leader no strikes on the board. You're looking real good for answers up there 100 teenagers were surveyed and asked the name the best place for pizza in Sheboygan County What do you think Nicky's Nicky's is Nicky's up there? No Nicky's but you still got two strikes left keep it rolling here name the best place for pizza in Sheboygan County Luigi's Luigi's excellent pizza Luigi's are they up there? Jake our number one answer man two strikes left. You're looking good name best place for pizza in Sheboygan County I have to go to Domino's Domino's got Domino's up there Domino's no Domino's well If they're teenagers, you know, we don't know You serve and they give you their best answers Domino's might be good, right? Name the best place for pizza in Sheboygan County to keep things rolling here Little Caesars is Little Caesars pizza up there I think he's got a mean streak in him. Did you see how he did that one? Yeah. All right. Well done though Well done. That's three strikes. Namex got a chance to steal. Did you have a chance to confer? Looking good everyone's smiling For the steal and to match things up a little bit point-wise here 100 teens were surveyed name the best place for pizza in Sheboygan County Pizza Ranch? Pizza Ranch! Namex team one gets the points and the steal number eight Dio Maly's and number six All right, well done And the point total Somebody left some glasses up here by the way lost and found if you're missing some glasses question number three fifth graders were surveyed Name a food you do not have to chew but swallow pudding is putting on the board team one Yes All right, there's five answers better. I'm gonna read it just as it was provided to me Fifth graders were surveyed I think like a fifth grader name of food you do not have to chew but swallow Jell-O is Jell-O on the board That's correct. Do you like to play or pass? Pass pass you're gonna pass. All right. Thank you There's the two up there. I can read that up there that that reads a little better name of food You do not have to chew to swallow fifth graders Linda macaroni macaroni how many of us don't chew macaroni May there may be people in here that don't and remember these were fifth graders that were surveyed So this could be an excellent answer in his macaroni up there. We got noodles. We got Jell-O. We got pudding name of food You do not chew to swallow Stephanie. What do you think? candy candy How about candy we got candy on the board that would be your first strike, but you're still looking good Name of food you do not have to chew to swallow ice cream ice cream is ice cream up there Number two answer well done only one strike This is for the win potentially, but there's still three answers up there name of food You do not have to chew to swallow soup soup show me the soup Very good two left two strikes How are you feeling about the pressure right now? All right There's about three million viewers watching this right now Name a food you do not have to chew to swallow cheese That's your boy County. You could be up there No She's all right Well, you are the team leader Stephanie Obviously you were selected because you're probably the the leader of this group, right? Tough under pressure. You've got two strikes or they have a chance to steal they're conferring now Name a food you do not have to chew to swallow Popsicle show me a popsicle Those judges they're getting yeah, they're tired or getting mean or something aren't they? I thought it was a good answer, but they're having fun too. All right. We're over here wigwam Wigwam has a chance to steal For the win two answers on the board Bob did you conferred? Feeling good about this answer. All right, here we go name a food you do not have to chew to swallow Mashed potatoes show me the potatoes It wasn't up there It wasn't up there, which means knee Mac wins the round number seven Thank you everybody quickly very quickly Kate introduce your team This is Peter Danielle Dustin And over here Nia, I am Nia. We're from Lakeland College, and this is Gina John Anthony and Brent. All right. Thank you very much. We're gonna get rolling because we know times late two team leaders Please come forward. We have three questions. This is it. Let's hear it for him up All right quiet quiet 100 teens were surveyed Name a favorite brand of gum Festival Orbit is orbit up there Yes, number three answer Nia. So there's room for two more Bubble yum is there any bubble yum up there? Sorry, sorry Nia. Would you like to play or pass? They're gonna play okay Okay. Wow. Here we go This is our third day of this event. How's everybody holding up? Good All right. Well 100 teens were asked to name a favorite brand of gum. What do you think Peter five gum? Five gum is five gum up there Five gum has anybody in the audience heard of five gum? Yeah, I hadn't five gum good answer number one answer Wow Name a favorite brand of gum Daniel Trident Trident is trident up there Well done. I wonder if it gives them any advantage that they all work at a grocery store Dustin name a favorite brand of gum Dentine dentine is dentine up there Pat, how you doing pretty good probably don't chew a lot of gum in the meat department I'll bet you employees aren't allowed to chew gum at all when they're at work, right? Right. I like that. I like looks terrible. That's not what's always chewing on their old gum Just a personal observation Okay, 100 teens were surveyed name a favorite brand of gum I'm going back old here, but Wrigley Wrigley. I can remember Wrigley. Have a little Wrigley. I'm with you Pat I would have thought that was up there 100 teens 100 teens so obviously they don't chew a lot of Wrigley We're done 100 teens were surveyed name a favorite brand of gum Icebreaker icebreaker. We got any icebreaker up there. All right Lakeland College Chance to steal some of the best and brightest minds in Sheboygan County We've surveyed about a hundred teenagers and we asked them to name a favorite brand of gum You are the team leader. Yes. Are you prepared to have prepared and your answer is big red? Big red is big red up there. No big red Festival gets the points. I thought that was a good answer, but it wasn't up there. How about six? What do we got for six? Juicy number five question number two bring up the next two contestants, please What's that a little little commercial break? Let's go to number five. All right, and we're back 100 County residents were surveyed Name a US president other than Washington Lincoln or Obama Lakeland van Beeren Is van Beeren up there? I'm sorry. I Think Van Beeren wasn't he like the Lakeland College president or was there is or what's Van Beeren? Oh Why are you laughing? Is Van Beeren up there for those of you watching that is a president of the United States, but it wasn't up there to get on the board 100 County residents were surveyed. I know you were quick at the bell as well name us name a US president other than Washington Lincoln Kennedy Kennedy. Let's see Kennedy Yes, very good. Would you like to play?  This is the third and final question. No, it's not. It's only the second We're okay. We're okay. Don't feel too much pressure 100 County residents name a US president other than Washington Lincoln and Obama Carter show me president Carter Undustin name a US president other than Washington Lincoln or Bill Clinton Bill Clinton president Clinton very good. I think we're just gonna keep rolling here Pat, what do you think name a president other than Washington Lincoln or Obama George W. Bush George W. Bush Took him well didn't Are we doing up there George W. Bush. All right We have four answers on the board no strikes your rolling festival foods name a US president other than Washington Lincoln or Obama Kate, what do you think Eisenhower Eisenhower is president Eisenhower up there? Certainly a president but not up there Peter Roosevelt Roosevelt he's got to be up there president Roosevelt very good Two for one chance there Daniel. I'm gonna go with the ever-controversial Nixon Nixon Show me Nixon. We're flying along only one strike couple left Pat name a US president other than I'm sorry Pat Wait your turn Dustin name a US president other than Washington Lincoln or Obama Well, we already talked about W. So I'm gonna go with Bush 41 Bush 41 Bush senior Bush senior Yes, all right Ronald Reagan is president Ronald Reagan on the board One answer well done Pat for the clean sweep Kate Name a US president other than Washington, Leek Lincoln or Obama five seconds Henry Ford is Henry Ford on the board All right coming down to Lakeland College We're gonna go with what you seem kind of in a hurry to give the answer How you doing good you're conferred everyone's good lots of smiles are right here.  What was number seven? Thomas Jefferson Wow All right, what do you do? What do you do a nice job and the point total? And the point total they that both these teams are already winners are they not Let's hear it out there on behalf of Rotary. We really appreciate you participating in your patience today with a couple little blips But I'll tell you we have so many good people working so hard To make this happen. So thanks for your patience a lot of good people here now We've got six questions to determine the Rotary survey says championship of the world event right now This is it. This is it You were all in the room earlier. Do you think we could just get right to the game or would you like to do? She said she didn't think she'd get past the first round I love that confidence. Okay, let's get going here Let's just get let's play let's play come on for Question number one 100 teens were surveyed in Sheboyton County or their abouts Name a favorite movie that came out during 2013. Yes Hunger Games is hunger games up there Team one that's correct Number one answer. Would you like to play or pass? They are going to pass. All right We get to come on down to NEMAC. NEMAC has how many employees does NEMAC have? 1400 I think you said that earlier to me today 1400 that's a lot of employees the mayor and I had a chance to tour NEMAC baby six eight months ago Incredible facility what going on? Yes. All right Stephanie They passed The number one answer is already on the board name a favorite movie that came out during 2013 Thor to Thor to Thor to is it up there? It is not up there Take your time on this now. Remember. This is the championship of the world round 100 teens teens were asked this question name a favorite movie that came out during 2013 oh and I said take your time. I didn't mean like take a long time And then just you know relax and take a few seconds Vicki Teenager what would they say in 2013 was a Favorite movie I need your answer five seconds. I don't have it. I don't have it Could be a Disney Okay, well, you never know Earlier today. There were some answers like I don't know that were up there Chris 100 teens were surveyed name a favorite movie that came out during 2013 There was a sequel to the Hobbit The Hobbit Hobbit to Hobbit a sequel There you go the Hobbit. Thank you very good 100 teens were asked name a favorite movie that came out during 2013 Despicable me to despicable me to Despicable me to did you see it? Yeah name a favorite movie That came out during 2013 cloudy with a chance of meatballs, too Could you hold it? Oh, don't give her the wrong on that yet. I want to hear this cloudy with a chance of meatballs, too Cloudy with a chance of meatballs, too. Come on. That's got to be up there How many in the audience heard of that movie cloudy really a lot of you? I am out of touch All right. Well, that was your third strike, but you left them only three on the board and obviously this is a tough question Festival foods K team leader have you conferred? You have an answer to name a favorite movie that came out during 2013 Frozen Number six Inferior all right nice job festival foods first to get on the board. What are the points look like? 71 question number two anybody's game Rotary survey says championship of the world 100 senior citizens were surveyed Or they're about Name a famous person from Sheboygan County Peter Team one herb Kohler team one. Yes Number one answer Peter. Would you like to play or pass? They're gonna pass. All right Name a favorite famous person from Sheboygan County now. All right, Stephanie Was up Vicki was about to hit the buzzer so you get the shot at this Vicki how long have you lived in Sheboygan County? Most of your life so like 25 26 years. Yeah, okay, so Vicki's been in Sheboygan County for about 25 years I'm sure this is an easy question name a famous person from Sheboygan County Mayor Ryan We all know there's a little Dead our seniors say Mayor Ryan Vicki knows your stuff Outstanding Outstanding Mike is Mike van der Steen here anymore. He'd be so happy to see this All right, Mayor Ryan number two answer on the board keep it rolling Chris 100 seniors were were surveyed name a famous person from Sheboygan County The only thing I can think of is David Kohler David Kohler David Kohler not a bad answer Certainly is a famous individual. That's for sure What going on at Kohler Linda? What going on at NIEMAC to do we have any famous celebrities from NIEMAC name a famous person from Sheboygan County You know what if you've only lived here a couple years, this is really unfair Yeah Sorry, we're gonna have to ask you for an answer name a famous person from Sheboygan County by seconds I Don't know is there someone named Walter Kohler Walter Kohler Is Walter Kohler on the board? Guess is better than none at all. All right, two strikes Chance for Festival foods to steal name a famous person from Sheboygan County 5 seconds Stephanie a Mr. French Mr. French is Mr. French on the board chance to steal festival foods They are conferring Kate is in her leadership chair Name a famous person from Sheboygan County Sam Decker Sam Decker is Sam Decker up there Job he's been having a tremendous career UW-Madison well done as well as Lutheran. All right stolen by festival foods number six Mary Alice Fox Can't say that jumps out at me number five Bomb and number three Little straighter. All right former backer. Well done. Well done in our points Next two players question number three Fifth graders were surveyed and asked name a musical instrument too big to carry on a plane Chris a tuba. We got a tuba up there Team two. Yes Number one answer play or pass neemak need to call play They're gonna play They're gonna play for those of us who played in band and carried big old instruments around I'm sure we can think of some answers to this name a musical instrument to bake to carry on a plane The bass drum the bass drum is the bass drum up there. We done nicely done Stephanie name a musical instrument according to fifth graders to bake to carry on a plane a piano a piano Show me Want to carry that on an old plane No, sir re okay fifth graders. You're on a roll. No strikes. No, no, uh, what do they call you strikes?  Strikes name a musical instrument to bake to carry on a plane an organ an organ Is there an organ up there similar to a piano? I wouldn't want to carry it right name a musical instrument to bake to carry on a plane one strike Trombone a trombone. I was hoping somebody say I played the trombone and carrying that dog-on thing around On the bus. Oh Could imagine carrying it on a plane trombone good answer. All right only one strike Name a musical instrument too big to carry on a plane Violin violin. I don't want to carry a violin on the plane. No, thank you. There are two strikes Neemak Maybe looking to get stolen from here if Stephanie doesn't keep it going name a musical instrument too big to carry on a plane The cello the cello Is the cello up there? Answer Stephanie keeps it alive Vicki two more answers name a musical instrument too big to carry on a plane Fifth graders Viola a viola is a viola up there three strikes Come on on down to festival foods They've conferred you have a hundred and thirty two points and this would give you a nice Lead if you're able to steal here two answers on the board name a musical instrument too big to carry on a plane a harp Do we have a harp? Best of all food steals they get the points number four Heritone finalized the scores And what's our toll? What's that Linda? Sure, we can put that up for you. Could you put number two on for Linda just for a second? Just give Linda a second to soak this in All right, I think that's good. Thank you. All right, Linda. Here we go 100 Rotarians were surveyed Name an animal that starts with the letter a Linda Art of her to That's correct Number one answer did that song work for Linda or what nicely done player player pass They're gonna pass nice answer Wow, okay name an animal Down to Pat Pat you work with animals all the time Inside That works the beat department if you missed that earlier.  Nice job Festival foods Moving right along here back to the team leader name an animal that starts with the letter a Antelope Antelope do we have antelope on the board? Here we go. Here we go Peter name an animal that starts with the letter a Alligator alligators alligator up there We're rolling we're rolling Danielle name an animal that starts with the letter a Anaconda Anaconda No, but only ones only your first strike lots of time you're name an animal that starts with the letter a What about an ant is there an ant up there? Two on the board Pat name an animal that starts with the letter a And Arabian Stallion you don't have many of these in the meat market. I don't know. No Arabian Up there. All right. I'm still got a strike left Still okay Okay, you remember the question? Yeah Name an animal that starts with the letter a armadillo Well, two strikes One answer on the board fourth question This potentially could seal the deal Peter Name an animal that starts with the letter a Five seconds. I'm drawing a blank. Do we have I'm drawing a blank up there? All right, Neemak chance to steal this is critical. I mean Critical, are we doing here? We're doing great All right, this is question number four, there's two more after this do it how does it work with the points? Do we know exactly how many points there are each time? Regardless, we're continuing right darn right. We are we why I can't hear your audience. Are we continuing after this? That we are Bet we are so it really doesn't matter what you answer here because we're still gonna continue and have fun But this would be huge name an animal that starts with the letter a alpaca Alpaca is alpaca on the board for the steel No That it was festival foods keeps the points number three was All right, here we go here we go. Let's keep rolling anything can happen All right question number five teens were surveyed teenagers Name the best place for an ice cream treat in Cheboyton County Pat Not festival team one Dairy Queen That's correct. A lot of room up there Name the best place for an ice cream treat in Cheboyton County and your answer is at a restaurant at a restaurant I'm very sorry player pass I thought you were just trying to kind of smoke Never know. All right, Vicki teens were surveyed teenagers any children 37 and 31 you're kidding and you've only been in Cheboyton County 26 years What woman woman I'm impressed Well, that's wonderful name the best place for an ice cream treat in Cheboyton County McDonald's McDonald's is McDonald's up there And it's there nicely done nicely done Keep it going Chris name the best place for an ice cream treat in Cheboyton County Coldstone Creamery Coldstone Creamery That is where my daughters love to go coldstone creamery good answer Linda culvers culvers is culvers on the board They're rolling They're rolling to left no strikes name the best place for an ice cream treat in Cheboyton County Sonic Sonic Sonic To up there yet Name the best place for an ice cream treat in Cheboyton County five seconds No answer straight That's all right Chris. You're still alive here name the best place for an ice cream treat in Cheboyton County I believe the name of the place is tillies tillies tillies with a T Tillies with a T All right chance for festival foods to once again steal from me man You guys are some of us You've been very effective and this would I gotta believe this would pretty much You know put the herd on things here name the best place for an ice cream treat in Cheboyton County What do you think it's south pier parlor south pier parlor? Nice job festival foods they get the steel number four All right the total points And looking to our judges and we continue to play is that correct all right? Well, I'm seeing different visible signals from different people from a point standpoint Can they get any more than I think we should call our champions of survey says for 2014. Let's hear it for Volunteers that have helped us out Want to thank me Mac for doing such a great job today and congratulate festival as they win Not only will you be able to display this lovely trophy at festival food show up here in Cheboyton For the calendar year until our contest to get next year, but you have won a $500 grand prize It's up to you how you guys want to take it you'd like to donate charity if you'd like to check We would like to take it to festival And you're welcome to do that. It's your winnings. Well, go down and you're kind of the second prize is $250 Okay, well with that we thank you again for another very successful survey says I think I leave it on this great display right here there you are


In this video, we're going to explain three more addressing modes of the AVR architecture. Let's just remember that addressing modes are those techniques that the microprocessor uses to access the operands that are specified by different fields of the instruction. And let's also remind that we're going to use the following notation. We are going to use the effective address of the operand, and we're going to represent it by ads of E.  We're going to refer to registers, and typically these are registers that are specified by these fields, so we're going to refer to them as the R sub f1, meaning the register specified by the field f1 in the instruction. And then we're going to refer to program memory like this, like if it were an array with an address in square brackets, same thing for the data memory with an address in square brackets. And finally, when there is an operation over a register, we're going to denote it with this arrow like this. So with this notation, let's now describe three more addressing modes. The first one is called data indirect with post increment. Now what happens when an instruction has this addressing mode is the following. This is the instruction. The instruction has one field in it that encodes, let's call it f1. This instruction, which by the way has typically 16 bits, this field encodes one of the registers in the register file. So this is the register file. We go to one of these registers, and in one of these registers what we access is the address that we use to go to the data memory, and there is the operand. Now so far what we have said, this is exactly the addressing mode that is known as data indirect. Now what is the difference data indirect with post increment, this is precisely the difference. There is a post increment meaning that once the address has been obtained from the register, this address is then given to an adder, and this adder is going to increment by one this value, and most importantly, this new address is loaded into the register. So we follow the notation described here to capture what happens here. We're going to say that the effective address of the operand is going to be the content of the register specified by the field f1. The operand is actually in the data memory, and the address is specified by rf1, but and this is the most important difference, now rf1, we use the notation we introduced here, takes the value of rf1 plus one, or in other words, gets incremented. An example of the syntax typically used in assembly program would be this one, the instruction LD, R12 comma. Now this plus over here is the one denoting that this instruction should use the data indirect with post increment. Now careful because the fact that this register contains an address, it means that it has to have 16 bits, therefore the restriction is that only registers x, y, and z can be used with this addressing mode. Okay, once we describe this addressing mode, there is another addressing mode which is very similar, not identical but is very similar or analogous, which is the data indirect, but this time with pre decrement. Now with the name we can pretty much deduct exactly what is happening here. Again we have an instruction, typically 16 bits, we have one fill on this instruction, let's call it f1. This fill in the instruction points again to a register in the register file. Now what happens here is different, the value that gets accessed from this register now is connected to a subtraction which decrements in one unit that value and then that unit, the result is what is used to access data memory and obtain the operand. And again similar to what happens here, this operation that decreases, now the big difference is that this is decreased before the access to memory is done, but still this new value is reloaded as the new value of this register here. So following our notation, the effective address right now is our f1 minus 1 which is the result, this would be the effective address, the result of subtracting one unit from the value obtained from the register, the operand of course is in data memory in the address we wrote before and the most important thing now is that our f1 gets modified with its own value minus 1. Now an example of an instruction using this addressing mode would be LD R12 minus X. So this minus here used as a prefix for X is the one that is telling us that it's going to be pre decremented. Now it's interesting because this syntax is already telling us the order of the modification of the register. Here we put the plus sign after the X because it's a post increment whereas in here we put the minus sign before the X because the register is pre decremented. And the next addressing mode that we're going to describe is called data indirect with displacement. And this is a very interesting one. In this case the instruction has again 16 bits, but now we have two fields. Let's call it f1 and f2. The first field is going to still point to one of the registers in the register file. From that register we're going to obtain a value, but now this value gets added to the value obtained from field 2 of the instruction. This is what we call the displacement. And the resulting number is what we use to access data memory. And right here we have the operand. Now we follow the notation that we've been using so far. The effective address of this operand is rf1 plus the value of this field. In this case it would be inst f2. And of course the operand it's going to be in the data memory in the position captured by this expression rf1 plus inst f2. Remember inst f2 refers to the instruction field f2. Now three very interesting things about this instruction. First no register is modified as opposed to the other two addressing modes we discussed before. In here there is no feedback of the value back to the register. The register is left intact. The other interesting restriction is that only registers y and z can be used. This is important because it's a little bit of an anomaly. And this operation and this one which I forgot to write it, only x, y and z can be used. So in these two addressing modes any of these three registers can be used. However, in the data indirect with displacement only y and z, this is a restriction derived from the architecture. And the final restriction is that the displacement as you can imagine, this is only 16 bits, can only be represented with certain amount of bits, in this case is 6 bits. Which means the value has to be between 0 and 63. And an example of an instruction using this addressing mode would be ldd r12, z plus 24 for example. So this constant over here is the displacement. And this is also the one that must satisfy being in the range from 0 to 63.


The INDEX survey is important to me as it will help plan how best to support our students and build learning communities using digital tools. As an advocate of teaching enhanced learning, understanding students' digital experience is a key element to designing appropriate resources and assessment. As we work on the next generation digital architecture for hibernia college the INDEX survey could provide invaluable insights on the way forward. Hi guys, we look forward to hearing what support you think is useful for students and what your views are on digital and virtual learning. As digital learning lecturer here at Mendenthi University I'm really happy to hear that this survey is going to inform our pedagogy and also help us to look at our infrastructure here. The INDEX survey is important to me because it will help us understand which digital learning tools our students find most useful. Hi guys, the college is in european and on digital learning this is the opportunity to have her save and help them to improve it. I teach information literacy and part of our course we encourage students to take an active role in their learning and part of this active role is getting used to a different technology here in university. I feel that this survey is vitally important, especially for our practice we may feel that. The INDEX survey is important to me because it encourages real partnership in identifying and developing our digital needs. This is the first time that staff in higher education have come together with students to share their views on what digital platforms are delivering for teaching and learning and critically how they can be developed in the future. Hi, my name is George, I'm a business student here at CCT College Dublin I'm really looking forward to the results of the INDEX survey to see how technology is helping private colleges and beyond I'm also part of the CCT College INDEX group service. I'm contributing to the INDEX survey because I think it's important to have this conversation about how we use and how we can use digital technology in the university classroom. I'm really looking forward to this INDEX survey because I feel that technology is a key contributor to student success. As a lecturer in a small college I think it's important that I and my colleagues contribute to the INDEX survey and play a part in decision making around digital teaching and learning. Hi everyone, this is your opportunity to take part in a survey that will assist us to engage the current digital services that are available to students across universities in Ireland. We look forward to your valuable feedback that will help us improve the services currently. Thanks. The INDEX survey is important to me because this will give students an opportunity to have their voices heard and this in turn will enhance teaching and learning within the university. The INDEX survey is important to me because it will inform the direction of our digital education and learning analytics policy and ultimately I hope that it will support educational transformation and student success. Hello, I'm David Carpenter, CEO of Hibernia College and recent chair of HECA, the Higher Education Colleges Association. With over 4 billion people connected online today and is no surprise, digital technology is now an integral part of our lives. Higher Education Colleges are investing in digital technologies to build educational materials for teaching and learning, to teach learners and to regulate courses based on student centre learning strategies. From simple adoption of in-person technology instruction to complex adoption using lecture capture, online chat, discussion boards and social networking services the higher education sector adopts blended learning as a norm to improve the effects of using the learning environment as more active approaches to drive student engagement. These in turn are designed to drive improvements in student satisfaction with the learning experience, improve student retention rates and improve overall academic performance. The INDEX survey provides a unique opportunity to use insights into student and staff experiences with the application of digital technologies in a higher education setting as a basis for future strategic decisions about digital initiatives and investments in higher education. In addition, it provides us with the opportunity to benchmark Ireland against countries such as the UK, Australia and New Zealand. I strongly encourage you to participate in the survey and help us to determine how we might build a digital future together. Thank you for taking this time to do so. My name is Joseph Rine, Chief Executive of Thea. Thea institutions are fully supportive of the National Forum's INDEX survey. Our institutions are all for student success and to that end we have to engage with collecting the data and building an evidence base around digital experience, digital capacity, digital literacy and all with the view of enhancing student success. To that end, I encourage all of our staff and our students in higher education to engage with the INDEX survey over these coming weeks. Thank you. The Union of Students in Ireland are delighted to support the INDEX survey. In its delays, the learning teaching experience can be enhanced and transformed through the use of modern technology. Students are learners, co-creators and innovators and technology has the power to aid them through their learning journey. We are excited to learn more about the national digital experience of students and those who support them in their learning. Please make the most of this opportunity to shape the future direction of digital learning and teaching and contribute to the survey.


made, uh, that would, uh, not have been made except for the last month rule.  This amount is also subject to a 10% additional tax. All right. Account beneficiary. So the account beneficiary is the individual on whose behalf the HSA was established. So obviously you're putting up an HSA, a high deductible health insurance. So who's the person that you're putting that in place on behalf of HSA? Generally, an HSA is a health savings account set up exclusively for paying the qualified medical expenses of the account beneficiary or the account beneficiaries, spouse or dependents. So then you have the technical issue of just basically setting up the HSA and obviously what is the actual HSA? A health savings and HSA is a health savings account, which is set up exclusively for paying the qualified medical expenses of the account beneficiary or the account beneficiary spouse or dependent distributions from an HSA. So now we're talking about the money that's coming out of the HSA, which again is the last point in time that we might consider. Is there going to be a tax consequence? Usually the question here being, do we have to include anything in income and is it subject to penalty? Distributions from an HSA used exclusively to pay qualified medical expenses of the account beneficiary, spouse or dependents are excludable from gross income. So that's good. So see the line 15 instructions for information on medical expenses of dependents not claimed on your return. So you can receive distributions from an HSA even if you are not currently eligible to have contributions made to the HSA. However, any part of a distribution not used to pay qualified medical expenses is includeable in gross income and is subject to an additional 20% tax unless an exception applies. So what are qualified medical expenses then? Generally qualified medical expenses for HSA purposes are unreimbursed medical expenses that could otherwise be deducted on schedule A form 1040. So you can look at the instructions for medical expenses on form 1040, which a lot of people don't have a lot of familiarity with because you might not be itemizing number one, if you're lower income or if you don't own a home at least and number two, because if you do own a home and you are itemizing and your income is high, then it also has a limitation that you have to clear or a floor that you have to clear. But in any case, you can look at those instructions and see the instructions for schedule a and publication 502 medical and dental expenses. Now whenever we get into these expenses for like medical stuff, it's kind of messy. It's very messy because you can get a doctor to say that you need anything, right? But look at look at these days they got they got doctors saying that you need to have fully functioning body parts that cut off and whatnot. It's crazy. So so you could find a doctor to say you could find a doctor to say that you need a trip to Hawaii or something like that and they'll be like, Oh, yeah, that's a medical expense, right? But obviously, you need a jacuzzi. I need a sauna in my home. That's a medic. So these questions come up like all the time. And there and there and sometimes there's court cases and people will argue as to whether it's a qualified medical expenses or not. So you can go into the into the craziness of basically asking whether or not this or that thing qualifies as a medical expense. But a lot of it has probably been mapped out if not in the law itself in court cases and whatnot, where the iris is arguing over whether something qualifies as a medical expense or not. This is also a weird area where people start to to treat things as diseases. When when I think it would be detrimental to treat them as a disease, like they start calling people obese as a disease, even though even when they're not even weren't technically obese before, which I think is not healthy to tell people that it's a disease because then they feel like and but then you get


It's in pursuit of human well-being that we started commerce. So commerce should always serve human well-being. Right now commerce is leading. For the health of the economy, we are surrendering the health of the human being. So commercial forces are deciding what you should eat, what you should drink and how you should live. It should never be so, but unfortunately we have chosen that model across the world today, that commercial forces are going to determine the nature of human existence. No, human consciousness should decide the nature of human existence and commercial forces should serve that purpose.


Hi, I'm Rebecca McKinnon, coming to you from the studios at the New America Foundation here in Washington DC. Now, we journalists, we have come to depend on the internet for pretty much everything that we do. As do researchers, as does everyone around the world increasingly, we depend on the internet for our personal lives, for our jobs, for our political lives as well. And in my recent book, Consent of the Network, The Worldwide Struggle for Internet Freedom, what I point out is that we tend to take the nature of the internet for granted. And my point is that not only do we need to be concerned about how we use the internet, but we need to be concerned about what the internet currently is and what it might become. We cannot count on the internet remaining a platform for free expression. It will only remain a platform for free expression. It will only remain a platform on which we can conduct critical independent journalism, critical independent research if we fight to make it so. What you can and cannot do on the internet today is the result of decisions made by programmers, made by engineers, made by the companies that run the internet services and platforms and devices that we depend on. It is shaped by the policy decisions made by governments, made by legislatures, and by the way people all around the world use the internet every day. And so if we want the internet to remain compatible with free expression, if we want the internet to remain compatible with dissent and a platform on which dissent or muckraking journalism, hard hitting investigative journalism can be possible, we need to work at it. So as journalists and as media researchers the challenge is not only do we need to be thinking about the fact that business models of news are changing and how to ensure that independent quality journalism can survive as a business, but we also have to be worried about this delivery platform on which the journalism is conducted both in terms of what we publish but also in terms of gathering information and communicating with people. Are we going to be able to communicate with sources confidentially or will it become increasingly impossible to be anonymous online or to be secure online? Are we going to be able to access information freely around the world? Is it going to be possible to publish content that challenges the power of the people who control networks either as governments or as companies? These are all open questions. And so as journalists not only do we need to be covering the power struggles in the physical world which we always have done, but we need to be covering the power struggles over our digital world and our digital lives. And this is a story I think that journalists are only learning to tell, learning to cover. And so the challenge I think for journalists is to figure out how to cover this story better so that the public understands the different forces that are shaping the internet that we depend on for communications. They understand what laws are being passed and how that affects what you can put online, transmit through the internet and what the consequences are, what choices companies are making that shape whether you have any privacy online, how your identity is manifested online, and what you can publish or not publish who defines acceptable speech in all its different ways. And oftentimes it's very powerful companies making private decisions about what is acceptable speech, about how your identity should be manifested without a great deal of public accountability or input. And this is all affecting journalism. This is all affecting people's civic lives around the world. And these are stories that we need to be covering and it's our civic duty as journalists to cover. And so I have a number of questions that I'd like to suggest that both journalists and media researchers might want to think more about going forward. And one of those questions is what kind of support and training do journalists need going forward in order to be able to cover the internet as a politically contested space in a more effective way so that the public understands what's going on and so that policymakers and actually media leaders themselves understand what is going on. And what are some of the research questions we need to be asking that media researchers could be gathering data about that would help us better understand the way power is being exercised across digital platforms and services upon who it's being exercised and what are the consequences and who is responsible. There are a lot of research questions we could be asking about that which ultimately all have consequences for whether journalists and media organizations can independently do their jobs. And finally what are the policy advocacy strategies involved and how does that interplay with the work of journalists and the work of media researchers. And my final point is I think that journalists and media organizations have long agreed that press freedom is something is an issue on which news organizations cannot be neutral because without press freedom we cannot do our jobs. And similarly without a free and open internet press freedom is not going to be on solid footing it's going to be on very shaky footing that could disintegrate and so therefore just as media organizations just as journalists and media researchers have been taking a stand on press freedom and freedom of speech for a very long time it's also similarly important to take a stand for a free and open and interconnected internet if we want press freedom and freedom of speech to be possible in the internet age. Thank you very much.


So, you guys probably noticed that the weather is cooperating with assignment one, so this is great, let's be inside and write synchronization primitive sort of weather, so I would encourage you to take advantage of it before it warms up next week, and then you won't want to be inside writing synchronization primitive. So what we're going to do today is we're going to finish up with the example that we left off with last time, which is the producer-consumer buffer. We'll look at how to safely allow multiple threads to access that shared state using a synchronization primitive, and then we're going to kind of pop up from this unit we've been doing on synchronization, which was time to help you with assignment one, and we're going to go back to talking about the system call interface and get through exec and wait and exit, so that's the goal for today. So we're kind of assignment one, we're pretty much done with the announcements, I think everything's working, for the couple of you that decided to wait until like yesterday to sign up for discourse, hopefully you're getting new emails from Auth0 with new tokens in them, but please make sure you can access that stuff. The other thing I'll just say, given the weather today, is just to remind you of the cancellation policy, so if Buffalo Public Schools are closed then we will not have class, and probably one of you guys should remind me about that, because I probably won't notice, I'll just be here and then you won't be, but you know, if you're wondering whether to come to campus and there's two feet of snow outside, if the Buffalo Public Schools are closed we will not have class. Alright, okay so let's go back to our example, so the producers and consumers are sharing a fixed size buffer, we want to make sure that happens safely, and the sort of invariance that we wanted to establish in this problem, were that if there's data in the buffer, and there's a consumer that's available to consume it, that consumer is busy, if there's space in the buffer and there's a producer with an item to put into the buffer, that producer can put it in. Otherwise the producers and consumers should wait, they should essentially sleep waiting for work to do. Okay, so here's where we started, and it's not a bad idea when you write a code like this, that you know needs to be multi-threaded to start with some skeleton code that doesn't need to be multi-threaded, so other than the while at the top and the bottom, this is pretty much what we want. The producer puts an item into the buffer, the consumer removes an item from the buffer, why am I maintaining a count here? That's one thing that if I was doing this in a single-threaded context, I wouldn't need to do, why, where is that going to come in handy in a minute? You want to guess? What is the count, first of all? What is the count supposed to, what is the count measuring? Yeah. The number of items in the buffer. So I pound to find some full constant that defines the size of the buffer, and so if the producer tries to put an item into the buffer and it's full, it needs to do something, if the consumer tries to withdraw an item from the buffer and it's empty, it needs to do something. Okay, what do you guys think is the right primitive here? There's a couple that could work, what's a good primitive, yeah? A condition variable, who agrees that that's a good primitive? Me too, what else could you use? You could use a semaphore. And the way to do this with a semaphore is not as intuitive as you might think, but you can, I think you would need maybe two. But to be honest, semaphores are not particularly useful when solving problems like this, frequently you'll find that a condition variable works better in most cases where you might think that you want to use a semaphore. There's a couple where it's not true, but I would encourage you, if you were thinking about using a semaphore, try to solve the problem with a condition variable. Condition variables in some way are a more general form of a semaphore, right? You could think of a semaphore as a special type of condition variable that forces threads to wait when the count is zero, whereas a condition variable can be very general. Okay, so the conditions here that require waiting, so there's three conditions the buffer can be in. If it's full, who has to wait? The writers or producers. If it's empty, who has to wait? The readers or consumers. And if it's in between, nobody has to wait, right? If it's in between, all they need to do is make sure that access to the count in particular is atomic. And in reality, well, I probably also want to make sure that access to the buffer is atomic. I'm not showing you the code for get and put, but those would have to do some synchronization on the internal buffer state itself to make sure that two gets don't return the same object or something like that. Okay, so let's try this. So I made modification use in a CV. So now what's going to happen, remember with the condition variable comes a lock. A lock is what protects the condition in between me checking it and going to sleep in this case. So I've created a lock and a condition variable. What I'm going to do, what the producer is going to do is when the count is full, it's going to wait on the condition variable. When the consumer, same thing. When the buffer is empty, it's going to wait on the condition variable. Why is it? So, okay, so I kind of understand this code, right? I acquire the lock here in the producer, I check the count, I call wait. Why is it safe to wake up and check the count again in this while? Yeah, so what does CV weight do to the lock? Why am I passing a lock to CV weight? What is CV weight going to do with the lock? Nothing, poop on it, I don't know. Yeah, what's that? Okay, it makes it atomic to get to the weight channel, but what's the semantics of CV weight? Well, let's not worry about the internals of the CV weight, but CV weight is going to drop the lock, right? If CV weight didn't drop the lock, what would happen to other producers or other consumers? Let's say that CV weight didn't drop the lock, what would happen to this system?  So if I'm holding the lock, can the condition change? No, because nobody can acquire the lock to produce or consume. So this is bad. So again, what does CV weight do? It releases the lock. When it wakes up, what does it do? Why is it safe to recheck the condition here at the top of the loop? Why don't I need another call to lock the choir here? Yeah. Because CV weight internally reacquires the lock. So CV weight returns with the lock held. CV weight has to be called with the lock held, and it returns with the lock held. So it's completely safe to sit in this loop, just CV weighting, checking the count, and also when I drop out of the loop, I still had the lock. And so I need to release it down here. Okay. So does this work? No, why not? Yeah, so there's no signal. When you're using condition variables, whether they're semaphores, locks, CVs, reader-writer locks, whatever, very often you have pairs of operations, and CVs are no different. What's the pair of operations you have to be cognizant of with a lock? Yeah, you guys thought I was going to say CV, but I tricked you, right? This is like jeopardy you buzzed into early. I said lock, what's the pair with a lock? Every time I acquire a lock, I need to release it. And this is great coding practice, right? So please, when you're writing your code for this assignment, when you write lock, acquire, you know, hopefully you're programming with your partner and your partner is pointing at the screen and saying, where are we going to release the lock? Because those should always go together. With the CV, the paired operations are, there's really two groups. One group consists of what operation? There are three operations in a CV. You have some non-trivial chance of getting this right, even if you're just guessing. Yeah, for Josh. Okay, so weight is in one camp. Weight stops me. What are the two things that can wake me up? Signal or broadcast, whatever. Wake one or wake all, okay? So here I've got a weight, but I have no signal. Ah, you guys, I should have to give you a dollar for every time that happens. Of course it does this too. So in this case, there is, sweet, okay? I don't know where my phone went though. Okay, so in this case, there's a weight, but no signal. Let me fix the problem. Good. Now, where do I want to put the signal? When does the condition change? In a way that's meaningful, right? So I need to call CV signal or CV broadcast. Where should I do that? I hear mumble, mumble, mumble. Not the correct answer, yeah. After the count changes, okay? So I can put it here and this will work. This is working code. What's the problem with it? This isn't ideal. So this would be the point in your Google interview where the interviewer says, okay, this works, but can you improve it? For Josh, I'm not calling on you again. Yeah. Right. So remember, we actually had three conditions. There is full, empty, and other. And the consumers only care when the condition changes from empty to other. And the producers only care when it changes from full to other. So this will work. But what will happen is that there will be cases where all, you know, essentially if I'm in between, then nobody should be in here, right? So for example, if the buffer is neither full nor empty and my change, my decrement of the count does not change it from full to empty, then nobody should be sleeping up here, right? Because everybody's falling through this check and putting their items into the buffer, okay? So let's try this, okay? So this is better. This avoids those spurious wake-ups. So what is the producer doing? The producer is saying, I'm only going to broadcast if I know that the condition changed. So if I'm the guy who put an item into the buffer and it was empty, I need to wake up people who are waiting to consume from it. Same thing at the bottom here. So if I'm the person who created a spot and a full buffer, I need to wake up the producers. So there's an interesting question here, and this came up when I was looking at the semaphore code today actually in some of the tests we wrote. So why not use CV signal? Would it be safe to use CV signal? So is it safe to use CV signal here? So what's the difference between CV broadcast and CV signal? Yeah, Rajesh. Oh, I said I wasn't calling in you anymore. Sorry, stop raising your hand. I'm fooling you. I only am caching about 10 seconds worth of state here. Yeah. Right. So in this case, I'm notifying everybody. And I'll say I have 10 producers that are all waiting there and the buffer is full. And now a consumer comes in and consumes one item out of that buffer, how many of those producers are going to get to proceed? One. Okay. I'm waking up all of them. So is this a good, do I want to do this? This is a good thing to do. Okay. So it turns out you can use CV signal here. I don't work. But there's this interesting interaction between the synchronization primitives and the scheduler that I want to point out here. So, and this is something, you know, you see and you want to kind of be cognizant of certain situations. If I use CV signal here, what's going to happen is that the weight channel code is going to pick a thread from the weight channel and choose it and make it runnable. The problem with that is let's say that there's 10 threads on the weight channel, but one of them is more important than the other threads. The weight channel code probably doesn't know that. What knows that is a piece of the system that we're going to talk about in a week or two, which is called the scheduler. But if I don't make all the threads runnable, then the scheduler doesn't even know that they were able to run. So if I take all 10 threads and I make them all runnable, what happens is that the scheduler then gets to say, aha, you're important, you're going to run, you're going to be able to produce, everybody else goes back to sleep. So this is a little bit of a trade-off here. The price of waking up fewer threads is that the weight channel code has to be trusted to make the right decision, it probably won't. The benefit of waking up all the threads is that I allow the scheduler, which knows more about the threads than I do, and we'll talk about how schedulers make scheduling decisions in a little while to make this a system, just a comment. Yeah, right. Yeah, you probably could. You could probably have some function that the scheduler exported was like, choose between these threads. Yeah, that would be possible. Any questions about this code before we go on? This is the end of synchronization. All right, so just let me make a couple of comments about how to approach these types of problems, because this assignment is not the last time that you will have to solve synchronization problems as part of these assignments. You'll have to solve them as part of assignment two and definitely as part of assignment three. So as we pointed out at the beginning of this example, there's a lot of cases in which you can use, even among the four primitives that you guys will have working by the end of assignment one, there's still cases where you can choose multiple primitives to use for a particular problem. And there's usually one primitive that just feels better. In some cases, the primitive won't work at all. There's certain problems that you just cannot solve with the lock because of the semantics of locks, where you can solve it with a CV or with a semaphore. So you're going to do this for assignment one, obviously. And again, so before you start writing a lot of code, my suggestion is kind of sit down, maybe sketch out things a little bit. And if here's a sign that you've used the wrong synchronization primitive, you're having to use other synchronization primitives. You said, oh, I'm going to solve this with a semaphore. Oh, wait, I also need a lock. Oh, wait, I also need a condition variable. And if you have three synchronization primitives trying to solve the same problem, the likelihood is one of them is just free writing, right? It's the others are doing the heavy lifting. One of them is just not helping. So back up and see if you can solve the problem in another way. Okay. In general, when solving this kind of problem, you know, the first thing to figure out is what do you want to be true? So we did this with the producer-consumer buffer example. We said, here are the constraints. Here's the things we want to be true about the world. Not only do I want there to be coherence in the buffer itself, but I want to make sure that threads go to sleep if they can't do something and wake up when they can. That's important. You could write that code. So another way to write the producer-consumer buffer is just to have the thread sit there spinning, you know, banging the buffer over and over again. Is there space? Is there space? Is there space? That's not what we wanted. The way we set up the problem, we don't want that to happen. We want threads to go to sleep when they don't have any work to do. Identify shared state. So this is actually really critical. If you don't know the things that are being shared between the threads that you're trying to synchronize, you really have no idea where to start, and you have no idea when threads are accessing things that are potentially unsafe. Now, there's times when even global state does not need to be synchronized because there's some other constraint that applies that means that it's only going to ever be touched by one thread. But frequently, any sort of global state that you introduce into your kernel, you need some kind of synchronization. So people that have been, you know, something of an example, people that have been booting their OS 161 kernel have probably noticed a synchronization problem. Can anybody describe what it is? What is shared state that is currently not properly synchronized until you finish parts of assignment one in your kernel? Yeah. What's that? Yeah, like the output from the screen. So you guys, if you've booted a kernel with multiple cores, you've seen that terribly interlaced output. It's kind of amazing. So the current scheduler is round robin. So what happens is the threads actually run 1, 2, 3, 4, 5, 6, 7, 8 over and over again, and so it's beautifully interleaved, right? I mean, you would always have a hard time getting that to work by, if you wrote it by hand. But that's not what you want to see. So even on a system as simple as the one that you're already booting, there is shared state, the console driver. And bad access to that causes that pattern, you see. Okay, choose a primitive. Maybe choose multiple primitives. Sort of work through a solution with a couple and see how clean it is. Pair your operations. So, Waking, Sleeping, Signal, Weight, Release, Lock, Unlock, PV. Same thing with a semaphore. If you don't have the right number of calls to P and V, the count is either going to go this way, in which case probably things won't sleep when they're supposed to, or it's going to go and everything is going to deadlock. So you always have to have paired calls to these two, to two ends of most of these primitives. And also watch out for cases where you need to access multiple resources.  So just these are things to be aware of. And try to convince yourself, you know, and this is something that we recommend when you think about the synchronization problems, come up with some of the corner cases first and convince yourself what should happen. So for a whale mating example that we use as part of assignment one, what happens if I start 10 males and 10 females, but no matchmakers, what should happen? And maybe try that with your code to make sure that it works properly. It does what you expect. Okay, I need questions about synchronization. Before we go on, this is the end of synchronization, but of course there'll be more fun this week and next. Questions? Yeah? In assignment one, it says to be careful about building synchronization primitives off of one another. Can you elaborate on that? Yeah, don't, in general. Other than spin locks. I mean, spin locks are kind of the basis of everything else, right? And then reader-writer locks. You probably can get away with it. Reader-writer locks are probably the case where you can layer on a couple of other primitives. I think it's because the spin lock is essential. Other way around, yeah. Yeah, yeah, yeah. Spin locks are useful as a building block for the other primitives. But again, don't build your locks using semaphores. Don't build your CVs using... I mean, CVs are trivial, right? CVs are very easy once you understand the weight channels. That's a good question. All right, so let me go back and we'll do a few slides of review here just to kind of like help everybody go back in time with me. So when we started talking about synchronization, we got here by talking about fork. And that was the first in a series of process-related system calls that constitute the process life cycle. So fork, exec, weight, and exit. So fork returns twice. You remember, returns zero to the child. And what does it return to the parent? The child's process ID. The child thread, and again, there are new variants of this to other things, but in original fork, the child's and the fork he will write. The child begins to execute it at the same point as the parent did. So this is kind of like the ultimate case where you have to start thinking about multithreading because once you call fork, you have two processes that are executing the same code. So there are two processes hitting this loop. One does one thing, the other does the other. But that's because we wrote it this way. If we didn't, you'd have two processes executing the same code. All contents of memory are identical initially, but that memory should not be shared between the child and parent. So the child and parent can go off in their separate ways and they don't affect each other anymore through shared memory. And they start by default with the same files open at the same position. And this allows them, if they want to, to set up sharing through things like pipes. So we talked about the fact that fork is expensive. Now today we're gonna put that in context because we're gonna talk about the next thing that frequently happens after fork and the reason why fork can seem so futile because it's copying all this state around. And what we're about to talk about is how processes change. We talked about some solutions to this. Let's just kind of review, okay? And then because processes are created through fork, every process other than one, which is in it has a parent. And so you can rebuild all the processes back into a tree and here's what that looks like on a typical system. Any questions about this? We go on. Any questions about fork? Somebody remembers fork well. Okay. So the next thing, the next couple things we're gonna talk about are the rest of the process life. Like it was a little faster than fork, I hope. That includes how processes change and then how processes exit and a little bit of communication that goes on around exit. So obviously if you just had fork, this is one of my favorite slides all semester, it's still stupid, right? You just have like a lot of copies, I should do more, right? More. You just have a lot of copies of the same process and that wouldn't be a very interesting system. So the way processes change, the way a process gets to execute some other piece of code is by through a system called exec. And exec is actually a family of system calls. If you look at man exec, there's like exec with 10 different endings to it. Exec v e, exec, and that has to do with how the environment gets passed from the old process to the new process at exec. So this family of system calls, it replaces, it is a process saying, I want to be different. I want to replace my contents based on a blueprint that's laid out in this file. And if you've ever wondered what's in a binary, has anyone ever accidentally opened a binary file on their computer or something? Has anyone actually intentionally inspected binary files using the tools that are designed to do this so it just doesn't look like a bunch of gobbledygook and like break vim? Oh, you should try it. That's kind of fun. So there are actually great tools and there are tools that we give you that are part of those 161 tool chain that are designed to allow you to inspect the contents of an executable. As you would expect, the executable is a highly, highly structured file. The best way, the way I like to think about exec is that, and the binaries that exec uses is that these binaries contain a blueprint. So it's like someone gave you a blueprint to build a house and that blueprint needs to describe exactly what the house looks like, down to where the furniture is and everything. And the operating system is responsible for taking that and creating a process that replaces the process that called exec. So some of it is all sorts of things that are in the ELF binary, but mainly the ELF binary contains a couple of things. One of them is instructions on the contents of memory. So the binary says, here's a chunk of data and I want you to put that at exactly this location in my address space. So when we come back and talk about virtual memory, this will make a little bit more sense, but you can imagine that when the process starts executing, it's gonna refer to contents of its own address space using these, you know, addresses, memory addresses, and it wants to make sure that those things are what it expects. So for example, a lot of the contents of the processes memory initially are its code. And if the code isn't copied correctly, then the process doesn't execute properly. The ELF also tells the system where is the entry point? So when I actually start executing the first thread in this process, what's the first instruction it should load? And there are standard layouts that a lot of processes use by default. So if you compile something using GCC, GCC kind of puts things in standard places, but really you can pretty much layout things however you want. And as long as the file is a valid ELF executable, the operating system will follow your instructions as it sets things up. So ELF, everyone's heard of ELF as the executable and linkable format. And ELF describes not only binaries, which are things that are actually executable, but also libraries, including the shared libraries that a lot of programs rely on to function. I wish there was time in this class to do like a week on linking and loading. Does anyone actually understand how that works? It's pretty cool actually. When I took this class we actually talked about, it gets really gnarly and it's kind of neat. You can imagine like how do I take a library, binary code, and load it into a processes address space given that process A, B, and C may want to put it in different places. So that's the real challenge, particularly for building shared libraries is how do you make them relocatable so they can kind of go anywhere. So that's neat. But anyway, we're not gonna talk about it. Okay. So here's a helpful tool that's available on your system. It probably isn't available on your system, maybe. If it isn't you can install it. It's called Read ELF. And let's look at something like Bin True. So I'm asking Read ELF to tell me about this particular ELF binary. And here's some of the things that we talked about. So the ELF file type isn't executable. What would be another type? We just talked about this. Like a library, like a loadable library or shared library. What's that? DLN? Yeah, Windows, yes, yeah. So on Windows, I think Windows, well, I shouldn't say anything about Windows because I know little about Windows, but on Windows I think a DLL is pretty much equivalent to a loadable shared library on Linux. This is something that's running on Unix on our loading site system. So the entry point, what is this? So, well, okay, so this stuff down here is really more describing the contents of memory. But again, what's the entry point? It's a single address. What is that? What's that? So that's the first instruction that the first thread will execute when this process starts. So one of the last steps, when I set up everything, I copy all the contents in to memory for the process. And then one of the last things I do is create a thread and start it in that exact location. So that's the first thread that's gonna start to execute when the program runs. So been true, as you remember, is pretty simple, but it still has eight program headers. So this is, oh man, oh boy, I have to kind of remember. Okay, so, and this kind of, remember when we looked at PMAP? So PMAP was telling us about the address space of the process that was executing. This is telling us about the information in the ELF file. So for example, the ELF file is not gonna contain dynamic things that are allocated at runtime, like dynamic structures or whatever stacks or things like that. The ELF contains the stuff that gets loaded in when the process is initialized. So as you have here, these are program headers. You notice that these are marked as readable and executable, so that's program code. And you'll see that the ELF file indicates the offset. So this is the offset in the file, right? So there's a little bit of header in the file and then that says, starting from this address, I want you to load this much data and I want you to put it right here. I don't know exactly why there's both a virtual and physical address here. This may be for systems that do weird things with memory, but you can think of this as being, this is where I want you to put, this is where I want you to put the contents of the file that start from here with this size. So it says, take this much stuff from the file and put it in my memory right here. You'll notice that the entry point for the file is inside this region. So it's actually a little bit above where this region starts, right? And so that's inside the code section. Okay, so this has a bunch of other information about sort of various things that I want to load. Now, this is interesting. So this says, requesting program interpreter. So the L file actually tells the system how it wants its loadable libraries to be loaded. And when I was putting these slides together, I went ahead, I thought that was kind of interesting and I tried to run it. So here's what happens when you try to run that. It's kind of cool. What I love is that it spews this long error message that concludes with, you probably did not mean to run this program, right? Cause this is a program that's used by the system to load shared libraries on behalf of a program, right? And again, unless we were gonna spend a week talking about linking to loaders, I just thought this was funny, right? I did intend to run this program, actually. And it was nice that it printed such a helpful error message. Okay, so one of the things, so the process calling exec, one of the things that it provides is the path to this binary that it wants. But exec also allows the parent to pass arguments to the, sorry, keep saying parent. It allows the process that calls exec to pass arguments to the new process it's about to become. So when I call exec, like if I was gonna run a program that had some arguments, I can provide arguments to that program. And the tricky thing is the kernel, and this will be you, your job in assignment two, has to get those arguments out of the process that called exec, save them somewhere, completely replace the address space of the process that called exec with the new blueprint that I got from the Elf file, and then load those saved arguments in. And I'll have a slide about this in a minute, but you will think about this quite a bit when you do assignment two. So if you've ever wondered like where does, where do the arguments to main come from? Has anyone ever wondered that? Never, just outer space, right? I mean, main receives arguments, they come from somewhere, if main didn't receive arguments that came from outside the program, the world would be pretty bored, right? You'd have to run, you'd have to create lots of different versions of every program with all the arguments sort of built into them. So that would be bad. But this is where main, this is where they come from. And there's a little bit of extra work that C-Library does to set things up for main, but essentially it's the kernel that provides arguments to main when main starts to run. And then exec is kind of an interesting dual of fork. Remember fork returns twice, exec does not return. There's nowhere to return to. The code that called exec is gone. It's history, it's been replaced by this new process. The new process has no idea what just happened. It's like, just woke up, here I am, here are some arguments that came from somewhere, outer space apparently. And I'm gonna start running, that's what happens. Okay, so here's my fancy diagram showing how that happens. Imagine this is the caller of exec and it's trying to run bin true. And imagine this is bash, this is my shell. And I'll come to this in a minute. We're gonna actually build a little very, very simple shell in class through a combination of fork and second week. So imagine that my shell, you asked it to run bin true. So actually what would have happened is my shell would have forked a copy of itself. That copy is what's gonna run bin true. Otherwise if I ran bin true directly from my shell what would happen? Let's say that the way your shell worked is it took the arguments that you typed in and it just called exec. What would happen? There'd be no shell anymore, right? Shell is gone.  So that would be sad. But the copy that the shell has forked of itself calls bin true. So the first thing I need to do is get these arguments that it wants to pass bin true out of the caller into the kernel.  Using the address space I've created from this blueprint that I found in the L file. Now bin true doesn't take arguments but just bear with me. I mean it probably, actually bin true probably happily takes arguments, it just doesn't do anything with them. So then I replace the address space of the caller and I copy the arguments into the new process in a place where the process is going to expect them. So this is really critical. Because when the process starts running, what you need to guarantee is that argv actually points to the argument array that was provided by the caller. And then I'm back and I'm running bin true and I hit the entry point and off I go. Any questions about this? Yeah, Ron. Of course you're getting a copy of the file table in the new process in the previous one. Yep, I can. Wait, when you run exactly, the arguments to be passed over presumably they already exist, why not just not delete them when you clear out the rest of the file table? Yes, so okay, so the arguments don't really have anything to do with the file table. The arguments are just in memory, right? But you're right, I mean the question is, I've already got these arguments in the caller, somewhere in caller's memory. Why not just leave them there? And you know, I mean you could try to do that. The problem is the new program may have, so there are a couple of places, the problems with that. One is that those arguments could be on the heap, for example, the new process has no heap yet. It hasn't started to run, right? So that would be interesting. And the arguments are probably either on my heap or on my stack, in which case I can't really leave them where they are, right? But you're right, I mean if they were in a memory location that was okay for the new process to use, I could just make sure that argument be pointed to them, right, but that's not what's typically done. It's a good point. Any other questions about exec? Okay, so now again by convention here, exec and there's a gazillion options to exec, but you can have exec run without changing the file table. And this is intentional so that I can go back to what we did with fork and pipes. Remember fork did all this work to preserve the file table so that the child and parent could communicate with each other. If exec undid all that, then that would be bad. So it turns out the default behavior would be exec and you should remember this for assignment too because people get super confused about this, write this down. Exec does not do anything to the file table, nothing. Leave it alone, there's no need to do anything to it. The new process has the same files open as the process that called exec. Now again there are exact variants that allow you to do all sorts of things like re-initialize the file table, whatever, but the exec that we're asking you guys to write does not have to do anything to the file. Okay, so let's go back to this simple shell or let's produce a simple shell. And this is, I'm not pretending this will run. You can look, so there is, if you try to read the code for bash, I suspect that you will get sad because I think it's complicated. I've never looked at it myself, but I can imagine that bash is a fairly mature shell is probably fairly complicated by now. However, there is a simple shell that you can read the code for, where is it? It's in your OS 161 distribution. Even that simple shell is, David added some features to it so it supports things like backgrounding now. I don't know why, but it's kind of nice. So, but this is, and this is way simpler than that, but fundamentally the core loop of a shell consists of just a couple of commands. I get some input, so I would probably draw the prompt and then you would type something. Then what I'm going to do is I'm gonna call fork because remember, if I just exec that input, I'm gone. There's no shell no more. So what I wanna do is I wanna create a copy of myself and if I'm the child, I'm going to call exec and try to run the command that you gave me. So this is almost what we need for a shell. Any questions about this? Just a couple of things that we're missing here though, but we'll come back to that, okay? So the hardest part about exec is making sure that exec can fail and the exec can fail correctly. So for example, if I get, let's say, you can think about exec as like, you say, here's a blueprint for a new house. I want you to replace my old house. So I'm gonna go away for a week and when I come back, I expect there to be a new house. Now, you might not be able to build the house I gave you. There might be a problem, but what I don't want to come back to is an empty hole in the ground because you said, well, I got done tearing down your old house but I couldn't build the new one, right? So when I come back, I either want there to be a new house or the old house that I left there and exec pretty much has the same challenge. Of course, anyway, I mean, exec has memory and it's a computer so it's not quite the, the metaphor is not quite perfect. But what I want to make sure is that if exec fails at any point for any reason, I can return to the caller and that's the one case where exec will return, and success, exec does not return on failure, it returns to the caller. Okay, so now we've seen how processes are born and how they change and the last component of this is exit, death. How do I get rid of a process? And processes signal to the kernel that they are finished using another system call called exit, pretty simple. The only thing that's interesting about exit is that a process gets to, and this is quite useful, it's a very small amount of information but it's quite useful, a process gets to report something about how it died.  And the only information that gets reported by exit is this one value, just a return code or an exit code and those exit codes, the typical semantics of exit codes that are very well established at least on Unix-like systems are that zero means what? Zero means I died a natural death and everything was fine. Anything other than zero means that something bad happened or interesting and how that maps on to the actual meaning is totally depends on the program. So you can certainly run mad to find out exactly what the exit code returned by your program means. So the question is where does this exit code go? I call exit, I tell exit allows the process to tell the kernel why it died who does the kernel tell? Nobody just says, oh, that's too bad. I'm sorry, I'll just get rid of that exit code. Who does the kernel tell? Or who is allowed to find out? So remember we talked about the parent and child having a special relationship. And one aspect of that is that the parent process is guaranteed to be able to find out why one of its child, or to find its child exit. Try that again. The parent is guaranteed to be able to receive the exit code generated by its child. Now there's a bunch of other processes on the system and some of them may or may not be interested in why a particular process executed and that's fine. And they may or may not be able to find out why that process executed, but there is exit. But there's one process that's guaranteed to be able to find out and that's the parent. And how the parent finds out is the last piece of this and that's wait.  Does anyone even know about Lilydale?  There's a spiritual community that's like, I don't know, maybe half an hour from here. So it's a town, it's a very cute town actually.   If you haven't been there while you're in Buffalo, I would encourage you to visit, it's pretty cool. So Mike Buckley, he used to teach in this department, he insisted that it was very funny. For years he was telling my wife and I about this, oh we've gotta go to Lilydale, you guys are really gonna like it. And then we got there and he was totally freaked out and wanted to leave right away. So it was really strange. And it was pretty creepy I have to say. But go there. So this is kind of how the parent can get in touch with the child through the afterlife, right?  Everything about the child has been cleaned up. Everything, the address space is gone, the file tables are gone, whatever. There's just one little piece of information that's left there kind of swirling in the ether. And that's this exocode. So when a process calls exit, the kernel maintains the exocode until the parent calls wait. Or in certain cases until the parent exits, in which case I figure if the parent exits without calling wait, then the parent is no longer interested in its child. That happens, it's sad, but okay. So the parent retrieves this exocode by calling wait. Now remember, what did fork return to the parent? The process ID of the child. So this is where this gets used. Because a parent can have a bunch of children, right?  You can start off 10 different things in the background. All of those processes are children of the shell.  And the way I do that is by using its process ID. So when I call wait, what'll happen is by default, wait will actually do what it indicates. It'll wait for the child to die. Now we're getting morbid. And then return the exocode that was returned by the child. If the child has already died, already exited, then it will return immediately and it will return the exocode. Now, what's one interesting consequence of this? So remember I have these process IDs. And process IDs, you know, you might have thought, well, what are the semantics of a process ID? Clearly while a process is running, its IDs shouldn't change. But can I remove a process's ID and hand out the same ID to a new process immediately after it exits? Why not? Someone wanna venture a guess? Yeah. Yeah, so it turns out I actually have to wait until its exit code is retrieved. And the reason is, let's say that I'm a parent and I create child four. And then the kernel, child four exits. And the kernel says, you know what? I like child four. I have fond memories of child four. I'm gonna create a new process for. And that process is the child of the same parent. So now when the parent goes to call wait, it says wait for. Actually I should have choose five or something. Anyway, so it calls wait for. And the kernel goes, I have no idea what you want. Because I have exit codes for two processes four here, which one do you want? So I can't reclaim process IDs until the exit code is gone. Because otherwise the parent can't uniquely identify the child. So these two system calls I'm almost done are typically sort of considered together because when you combine them together, they remove all traces of the process from the system, executes sort of most of the stuff, and wait does the rest, okay? Okay, I'll finish this next time. So I'll see you guys on Friday. Good luck with assignment one.