Now, as gunshots echo across the windswept snow-covered reaches of the wild northwest, Quakerpuff wheat and Quakerpuff rice, the breakfast cereal shot from guns, present the challenge of the Yukon. It's Yukon King, swiftness and strongest lead dog of the northwest, blazing the trail for Sergeant Preston of the northwest mounted police in his relentless pursuit of lawbreakers. Un-King, on you have gained! Gold, gold discovered in the Yukon, a stampede to the Klondike in the wild race for riches. Back to the days of the gold rush, with Quakerpuff wheat and Quakerpuff rice, bringing you the adventures of Sergeant Preston and his wonder dog Yukon King, as they meet the challenge of the Yukon. It's the way Quakerpuff wheat or Quakerpuff rice disappears at breakfast time. These ready to serve cereals hit the spot from first to last delicious spoonful. Yes, wheat or rice shot from guns is exploded up to eight times normal size to make it crisp and tender. Tomorrow morning, fill a bowl with Quakerpuff wheat or Quakerpuff rice. Top with fruit, like say, sliced bananas. Add milk or cream and sugar. Talk about swell tasting. Say, just you watch it disappear, but fast. Hobo was a big dog, a cross between a St. Bernard and a Husky. He was extremely likable. He had hundreds of friends in and around Dawson, and he was welcomed wherever he went. But he never stayed in one place for long. One of the worst-mounted headquarters was one of his regular stops, however. He had a great admiration for King and for Sergeant Preston, and he would always bring the Sergeant a present. Hey, Sergeant, what are that big dog coming down the street? Virgin. Oh, they weren't pointing. Oh, yes, that's Hobo. Here comes Hobo King. Hey, who does he belong to? No one. No one? What a lead dog you'd make. That's where you're wrong, Jim. Not that he hasn't been broken to harness he has, and he doesn't mind hard work. Why shouldn't he make a good lead? Because there isn't a leash or a run that can hold him. He's afflicted with wanderlust. Sometimes it hits him even when he's in the harness. The rabbit should cross his trail. He'd run into the woods after to forget all about the sled behind him. But he could be trained. Just try it. He's always terribly ashamed when he does something wrong, and he asks so hard to be forgiven that you can't possibly punish him. I could get tough with him. Perhaps it wouldn't help, though. He'd be doing the same thing again 15 minutes later. Oh, here he comes. What's that in his mouth? A present for me. He always brings one to pay for his suffer. Well, what is it? There's no telling. This time it's... Oh. It's a dead fish. Yes, as ripe as they come. Thank you, Hobo. You thank him? Well, he probably considers it a very valuable gift. King, take it into the woods and bury it. King had to bury most of the presents that Hobo brought the sergeant. But Hobo continued to bring them because he was always getting into the sergeant's debt. For instance, one afternoon, as King and the sergeant were walking down Front Street, they saw a prospector who was leaving a pack horse lashing out at Hobo with a long whip. Come on, King. Let's see what Hobo's up to now. What's the matter with you? I'm freezing. Get away from my horse. I'll show you. What's the matter here? Oh, that dog. I don't know what's the matter with him.  King, make him be quiet here. There, he'll behave. Now, let me explain about Hobo and old Red here. You just bought Red, didn't you? Well, yes, sergeant. The day before yesterday, that is. From Cherokee Bill. How shy, sergeant. Well, one day about a year ago, Cherokee was leading old Red down the street and Hobo came up to say hello. Red had a pack saddle on, but he wasn't loaded just as he is today. Hobo had a little cut on his front paw and he was limping, so Cherokee asked him if he'd like a ride. Then he lifted the dog up on the horse's back and he rolled the whole length of front street. And ever since then, if Cherokee were leading Red, and if he weren't carrying supplies, Hobo would get a ride. That's what he wants now. A ride? Yes. Ha, ha, ha! Of all the highfalutin' dogs, Hobo takes the cake. A ride he wants. Well, if old Red don't mind, I don't. You could have your ride, Hobo. Get going, everybody.  I swear, sergeant, I never saw the like before. Well, come on, Red. Here's Majesty wants to see the town. The prospector started down the street, chuckling to himself. But in Hobo's mind, it was the sergeant who had saved him from a whipping and had arranged the ride. The next morning, young Constable Downey called the sergeant to the window of the barracks. Cover and take a look, sergeant. Your friend Hobo's bringing you another present. I was afraid of that. I did him a good turn yesterday. What is it this time? Looks like a bundle of clothes. Hobo! What's the matter? That's a baby! It was true. Hobo was trotting toward the barracks, carrying the Martin's year-old daughter by the back of her dress. A little girl crowed and gurgled and was having a wonderful time until the sergeant reached her and lifted her in his arms. Then, she started to cry. Thank you, Hobo. Doesn't seem to be a little mad, perhaps. I think she was enjoying her ride. Nancy Martin, her mother and father lived just outside of town on the river. Take her home. Hey, here comes a woman. See the mother? Oh, yes. Hello, Mrs. Martin. Oh, is she all right, sergeant? Here, I'll take her. There she is. She hasn't been hurt, I'm sure. Hold on this carrying her by the back of a dress. Yes, I saw that. I knew he wouldn't hurt her.  King wouldn't do a thing like that. You ought to be ashamed of yourselves. Don't look at me like that. I didn't mean any harm. What happened? Why, Nancy was playing outside the cabin and I was baking some bread. I went inside to see how it was coming along and when I came out, well, the little tyke had crawled all the way to the bank of the river. Hobo was watching her and just as she reached the very edge, he picked her up by the dress and started toward town with her. I called to him, but he didn't pay the slightest bit of attention. He kept right on going. Now, why do you suppose he brought Nancy here? Well, he may have thought she was lost but we'd take her home. Play and sing. Could it be he's smart instead of dumb? No, no, I could never believe that. But you did save her from falling in the river, Hobo, and you deserve a reward. Now, you come home with me and I'll give you a good dinner. Come on now. Goodbye, Sergeant. Goodbye, Mrs. Martin. Sergeant. Yes, Constable. You better discourage Hobo from bringing you any more presents. I'll do my best, Constable. You can depend on that. But it was shortly after that that the cold weather set in and Sergeant Preston left Dawson for the first of his winter patrols. The patrol lasted nearly a month. On his last night out of Dawson, he made camp on the banks of the Yukon near Gonaway Creek. At one o'clock, King sprang to his feet and growled a warning. Instantly, the Sergeant was awake. What is it, boy? The fire had almost burned out. There was a light snow falling and the Sergeant was unable to see anything. Suddenly, King's tenseness relaxed. He barked and wagged his tail. A moment later, Hobo came rushing up to the Sergeant and dropped a hunting cap at the Sergeant's feet.  Now, just where'd you get this? Hobo raced around the campfire in a wide circle, barking a welcome. But the Sergeant's expression changed as he examined Hobo's gift. Hey there. There's a big stain. Frozen, of course, but it's blood. Hobo, come here. Come here this minute. Take it, Hobo. Go on. Take it back. Hobo thought the Sergeant was inviting him to play. He picked up the cap, raced around the campfire once more, and then dropped the cap at the Sergeant's feet again. Oh, fine. A cooperation from him, King. Guess I'll have to leave it up to you, boy. Here, smell. Oh, fine, King. Fine. King understood. The Sergeant wanted him to follow the scent on the cap. He lifted his nose to the wind that was blowing from the north. There was no help there. Nothing doing, King. No clue in the breeze. Oh, that's all right, boy. Hobo's tracks won't be completely covered over yet. We can follow them. Come on. The Sergeant took a small hurricane ladder and from his sled lit it and started south in the direction from which Hobo had come. He found the big dog's tracks and pointed them out to King. There, boy. That's the trail. Follow it. Oh, wait just a second, King. Let's have another look at you, Hobo.  Here's the end of a trace still snapped to it. You chew through this, Hobo. Give a harness to a sled. You chew through the traces. Now, where'd you pick up this cap? Go on, King. Follow the trail, boy. King started out with Hobo trotting by his side and the Sergeant following close behind. In 10 minutes, he was unable to see the tracks that Hobo had made, but King was following a scent and never hesitated. Half an hour later, they came to the edge of the forest. A little farther on, there was a clearing and in the clearing, the Sergeant could make out the dim shadow of a cabin. There was no light, but King growled. The Sergeant put out the hurricane ladder.  At the side of the cabin, there was a series of half-filled hollows in the snow. A dog team had burrowed here. I guess as you chew through your traces here, Hobo, the wind's blowing from the direction we've come. You decided to pay King and me a visit and we've brought your usual presents.  All right, boy. We'll take a look inside. As soon as the door was opened, King trotted in. It was impossible for the Sergeant to see anything. He stopped in the doorway to light the lantern once more. King was standing in the far corner. As the Sergeant walked toward him with the lantern, he turned. He looked up into the Sergeant's face and whimpered.  It was easy to see where the blood on the cap had come from now. The Sergeant turned the man over. He placed his ear against the man's chest. Still alive, King, but he's been badly beaten. They've got to get him to a hospital and they're fast. We'll continue our story in just a moment. A magician. Yes, on this empty table before me, by merely waving my magic wand, I shall produce a tiger. Cresto. Magic. Look. And now I shall instantly change this most ferocious animal of the cat family into the tamest. Cresto. Magic. Look. And now for the greatest feat of all. On the table are two bowls, cereal bowls. You see, they're empty. Now, in my right hand, I have two packages, big red and blue packages.   The ready-to-serve breakfast cereals shot from guns. Yes, there's no beaten this eaten. For breakfast, enjoy Quaker Puff wheat and Quaker Puff rice topped with milk or cream and your favorite fruit. These giant king-sized kernels of premium wheat or rice shot from guns are exploded eight times larger to make them crisp and tender. They're shot through and through with nut-like flavor, too. Best of all, you don't have to be a magician to enjoy wheat or rice shot from guns morning after morning. Simply ask mom right now to order those famous big red and blue packages with the smiling Quaker man on the front. He's your guarantee that you're getting the original, the one and only Quaker Puff rice and Quaker Puff wheat. Now to continue our story. It was eight o'clock when the sergeant reached the hospital in Dawson with a man he had found in the deserted cabin, but it was still quite dark. The sergeant waited for the doctor to complete his examination, and then he drove down Front Street toward Mary Milton's restaurant. Bobo ran along beside the team. There was a light in the restaurant, the only one in the block. It was still the middle of the night as Dawson was concerned. As the sergeant opened the door, he saw Mary sitting at one of the rear tables. She was crying. A middle-aged man was standing beside her, and the sergeant recognized him as Charles Martin, the manager of the trading company. Sergeant Preston. Yes, Charlie, good morning. This isn't a good morning for me. I was just about to go over to headquarters and report a robbery. Your store? He's been living in back of the store. Well, when I unlocked the place this morning, I found the safe wide open and all of the gold gone. Well, that doesn't mean Phil took it. Well, he's gone, Mary, and without saying a word. He told me he was going. But you've admitted that he wouldn't tell you where or why. I won't believe he stole your gold. Charlie, does this cap belong to Phil? Why, he wore one like it. Let me see. What's his last name? Camel, Phil Camel. Yes, I do. Where is he already? Mary, this is a strange case, and I have very little to work on.  What was that? Last night, it was about 10 o'clock. I was just getting ready to close up when he came in. I knew there was something wrong the moment I saw his face. Mary? Oh, hello, Phil. I'll be ready to go as soon as I put these dishes away. Mary, I... I have some work to finish up tonight. Tonight? Oh, but why? It isn't the first of the month or anything. I have to get my books up to date. I'm going away. What for? To buy birds? No, no, I'm all through with the company. Mary, this is goodbye for us. It's what? Something's happened. I thought maybe it was possible to forget and start all over up here. But that isn't true. I haven't told you anything about my past. You never ask any questions. Why should I? I wasn't interested in your past. But you guessed there was something wrong just because I didn't say anything. No, I didn't. And I still don't believe it. Or even if you have done something wrong, it doesn't matter now, you and I are all that matter. Our future. There isn't going to be any future for you and me. I mean it, Mary. This is goodbye. I'm leaving tonight. Oh, you can't! There's no sense in talking about it. Goodbye. That was all he said. He left me standing right here. I see. Now, what about the robbery, Charlie? Well, the safe was opened when I got to store this morning. The gold was gone. And so were most of Kill's belongings. That's all. Where is he, Sergeant? In the hospital. There was a cabin last night about 15 miles north of here. What? You mean he's hurt? He was unconscious then. He still is. He's been badly beaten up. A concussion. I don't know whether he stole your gold and not, Charlie, but he didn't have it with him. There had been other men at that cabin. Perhaps they have it now. I know the direction they took, but I had to bring Phil back here. I'm going to report to headquarters and then I'll hit the trail again. I'm going to talk to Mary. I'll see you both later. The first person the sergeant met when he opened the door at headquarters was young Constable Downey. Hello, Sergeant. Welcome back. Isn't that Hobo out there with King and the team? Yes. Where's the inspector? He's gone down a white horse. I've been in charge for the last few days, but now that you're here...  I'm working on a case. What? Robbery, perhaps murder. Sure thing. As the two men loaded the sergeant's sled with fresh supplies, the sergeant gave Downey a full report on the case. But there was one detail that stuck in the Constable's mind. It was Hobo's present that led you to camp. Yes. I may have a lead for you, Sergeant. What? I saw Hobo in town last night. He was pulling a sled, working as a lead. Jim, the man, the men who were driving the sled, what about them? Men, two of them. They were down the street of ways. Anything will help. Caraboo parkers, hoods were pulled up over their heads. Was Camel one of them? No, I'm sure of that. These were bigger men. But in town last night. Isn't there any chance of Camel talking? No, not for a while. No sense in the waiting. I know the men who were with him headed north from the cabin last night and there's only one town between here and the border. Forty miles. Right. Crowded with miners, too. You like looking for a needle in a haystack. Well, he knows them. He knows their team and when Hobo meets anyone he knows, he tells the world about it. I'll admit his testimony wouldn't amount to much in court, but if he says hello to two men with Caraboo parkers and I find gold on their sled, well, that's the only chance I have. Goodbye, Jim. Good luck, Sergeant. All right, King, up front, boy. Come on, Hobo, we need your help. I'm King! Late that afternoon in the hotel at Forty Mile, Hex Norwell burst into the room with Red Crocker. What's the matter with you? Monty just came into town. What about it? I knew he shouldn't have stopped here. You found another lead dog for us? I found the one that ran away. What? Yeah, he's with a Monty. What if the Redcoat found Campbell? Take it easy. What if Campbell taught? Dead men don't. But he wasn't dead when we left. He couldn't have lived for an hour in that coat. He might have. How come that big dog's with the Redcoat? Just attached himself the same way he did to us. Where is this Monty? He was driving his team around in bag. I'll take a look at him. There's a window at the end of the hall up here. There were a number of teams tied up in back of the hotel. And as the sergeant was unharnessing his, Hobo broke away from his side. Oh? Well, King, it looks as if Hobo's found some friends already. Just take a look at them, boy. I heard the sled they've been pulling. As the sergeant walked over to Hobo, the big dog proved that it wasn't impossible for him to learn a lesson. The episode of the Martin's baby had impressed on him that it was wrong to take things that belonged to other people, even to make the sergeant a present. The stained hunting cap was sticking out of the sergeant's parka. Hobo whimpered apologetically, gently pulled the cap from the sergeant's parka, and carried it over to the sled and dropped it there. Then he looked up into the sergeant's face and asked for his approval. That word belongs, Hobo, on this sled? Good boy. Now all I have to do is find out who owns this sledding team. And just in case they show up while I'm inside the hotel, you stand guard here, King. Understand, boy? Guard this sled. The sergeant started for the hotel. The two men watched him from the window on the second floor. I guess that proves it, doesn't it? That was Campbell's camp. I recognized it. The Mountie found him. He's talked to him. He's coming in here. No rest.  We've got to get out of here. How far would we get? No. We've got to take care of that Mountie before we leave. How? In the same way we took care of Campbell. He'll ask about us at the desk. He'll be coming up to our room. Well, we'll be waiting for him. Come on. The sergeant climbed the stairs to the second floor slowly. The gathering dusk made the long hall very dark. He had to look closely to make out the room numbers. 217 was near the back of the building. He knocked. Come on. The sergeant opened the door. There was a man inside sitting at a table riding by the light of an oil lamp. Are you Crocker? No. What do you want with him, sergeant? You must be Norwell. That's right.  Yes. As the sergeant stepped into the room, Red jumped on him from behind the door. He cut off his wind with a vice-like forearm around his neck and raised his gun to bring it down on the sergeant's head. I've got him. But yet you haven't? No. He struck Red when sailing over the sergeant's head and crashed into the table, locking it over. The sergeant jumped on top of him, twisting the gun from his grasp. There's nothing like guilt to make a man give himself away. You're under arrest. The second man stepped up behind the sergeant and brought his gun down on his head. I got him good. Not good enough for me. Don, he's out cold. We can leave him here. Hey, fire. What? The lamp that smashed the oil's burning. Stamp it out. No. I'll get the gold quick. Let the place burn. We'll lock him in here. Hurry up. There is no explanation for the sixth sense that always warned King the sergeant was in danger. The dog had been ordered to guard the stranger's sled. But his intelligence was such that he knew when to disobey an order. And yet he had no intention of leaving the sled unguarded. Hobo was commanded to take his place. And Hobo seemed to understand the command. At any rate, he took King's place as King ran toward the rear entrance of the hotel. The rear door was closed. King ran around to the front. Two men were entering the hotel, and King slipped in with them. He streaked across the lobby and up the stairs. Then, down the long hall to the room where the sergeant was lying unconscious, he leaped against the door. The room clerk had seen King enter. There was a rule against dogs in the hotel, and now the clerk came panting down the hall after him. He saw the smoke seeping under the bottom of the door. Come on in, Thunder. Fire. Hell, fire. Where's my key? The flames in the oil had crept as far as the table, and one leg was burning. The clerk hurried to put it out, but King went straight to his master and licked his face. I'll give you a hand in a second, Sergeant.   No, help me up. Okay. Where were the two men who were in here? Search me. They didn't come down the front stairs. And they must have used the back. I still have my gun. Yes. Let's go, King. Out in back of the hotel, Hobo stood at bay in front of the sled.  Grab hold of him. Pull him aside, Red. I'll teach him. I got the team harnessed hurt. He needs a safe treatment. We gave the sergeant... The blow knocked Hobo aside, but only for a second. For the first time in his life, he lost his temper, and he jumped it. Red had knocked him down. Shoot him. Shoot the car right here. No, don't dump that gun, or I'll do the shooting. Trust him. Drop it. It's okay. Put him up now, Hobo. Good dog. You two are under arrest in the name of the Queen. It was a week later that King and the sergeant stopped at the open door of Phil Campbell's room in the hospital. Mary was sitting at Phil's bedside, and the sergeant listened to their talk for a moment before he entered. Quiet, boy. Is it all clear now, darling? Not entirely. Well, Crocker and Norwell threatened to send me back to jail to help them rob the company safe. I told them they'd have to wait for my answer, but I had no intention of helping. I decided to go back to the States and serve the rest of my term. I was going to leave Dawson the night I said goodbye to him. I understand that, but afterwards... What happened afterwards that night? Well, I can't tell you much. I'd finished with the books, and I was just putting them back in the safe when they came in. They knocked me out. And took you with them when they left town in that cabin. Oh, Phil was so lucky. For Hobo and Sergeant Preston and King. Lucky, Mary? I'm still going back to take my medicine. A year isn't so long. We'll be waiting for you. We? Hobo and I, didn't I tell you? He seems to have settled down at my place. The whole town is surprised. I guess he never realized before what a nice place a restaurant could be. If you're there, Mary. Don't ever forget that, darling. It looks to me, King, as if the case is closed. In just a moment, Sergeant Preston will give you a preview of Monday's adventure. Fellows and girls, picture yourself up there in the Yukon. Dog sledding or riding hour after hour like Sergeant Preston. You'd soon find out that real stamina calls for a nourishing he-man breakfast. So check up on your breakfast tomorrow morning. Be sure it includes a delicious heaping bowlful of Quaker Puffed Wheat or Quaker Puffed Rice with milk or cream and fruit. Remember, in these famous cereal shot from guns, you get extra food values of restored natural great amounts of vitamin B1, niacin and iron. Ask for Quaker Puffed Wheat and Quaker Puffed Rice in the big red and blue Quaker packages. Never sold in bags or bulk. Listen Monday, when Sergeant Preston and Yukon King meet the challenge of the Yukon in the case the doctor disappears. When Phil Carver's little boy became seriously ill and Dr. McComb couldn't be located, King and I took on the job of tracking down the doctor. We didn't know that he was being held prison by a pair of dangerous outlaws, and that all of us, including Phil's family, would soon find ourselves at the outlaws' mercy. Be sure to hear this exciting adventure Monday. These radio dramas, a feature of the challenge of the Yukon Incorporated, are created and produced by George W. Trendall, directed by Fred Flower Day and edited by Fram Stryker. The part of Sergeant Preston is played by Paul Sutton. They are brought to you every Monday, Wednesday and Friday at the same time by Quaker Puff Wheat and Quaker Puff Rice. The breakfast cereals shot from guns. For a delicious hot breakfast, eat Quaker Oats. The giant of the cereals is Quaker Oats. Delicious, nutritious, makes you feel ambitious. The giant of the cereals is Quaker Oats.  Then start on good Quaker Oats breakfast tomorrow, because nourishing oatmeal gives you more growth and endurance than any other whole grain cereal. Remember, Quaker and Mother's Oats are the same. This is J. Michael wishing you good bye, good luck and good health from Quaker Puff Wheat and Quaker...


My name is Kathleen Lee and I am working in conjunction with the street medicine team and I do outreach. I'm a team lead. Right now I've got four to six people that outreach particular districts of the city and I'm their lead. The program is pretty new. The direction of the program is new. So it's in flux and we're developing a whole new program, not unlike when I first started at the library, how the program was pretty new and it's evolving as the library program had evolved as well. The library has made an impact in different parts of my life in many different ways. Like getting me out of the rain when I need to get out of the rain to changing the whole direction of my life, which is where I'm at today and it's directly responsible. The library and this program here is directly responsible for what I'm doing today. My partner and I had a business that failed in 2008 with the financial crisis and also attributing to that failure of our business was the fact that we had had a heroin addiction for about 15 years at that same time. So during the course of like nine months we lost our house, we lost the business, there was just no work and we were very accustomed to a pretty good lifestyle even though we had this drug addiction because we had pretty good jobs all the time. So anyway when all of a sudden done there and there's no more house, the house is empty, we've sold everything and all that, we came to San Francisco and through the social services of San Francisco we were able to clean up. The hot team picked us up as clients and put in a stabilization room. My case manager asked me, did I want to work at the library? And that's all he said and I thought, I can distinctly remember the conversation with my partner Susan going, what do they want me to do at the library? Shelf books? I mean, I don't get, you know, I had no idea. So I went home and I thought, well I can probably do this. It's money, you know, it's awaited. And it didn't take me very long to figure out that it was really quite an amazing opportunity and I was pretty good at it. I could connect with the people pretty well. It just opened doors for my whole life. So I know this is what I'm going to be doing until I stop working. There's really nothing quite as powerful as a shared experience. So if I know firsthand what the issues and not just the issues but that feeling that you have of being in kind of a survival state all the time, you don't really get much past that because it takes most all your efforts every day to just find a place to stay, find food, stay safe, to keep yourself contained in some kind of sanity. So you're always in a state of crisis all the time. It's just a matter of having the tools so you need to know the resources. Those are the kinds of things that you need to have a knowledge base so when you are approaching someone you actually have something to offer. So I can tell them where to go eat. I can tell them where to get clothes or whatever it is their needs are or where they can stay the night, where their shelters are, how to get into shelter, how to go find the housing list right here in the library. There's access to all those things right here so if I know those things then I have something to offer. Other things that I learned was how to push myself to stretch my own limitations or my own perceived limitations so how to learn to approach people that are strangers to me and make that work for both of us so I can answer a need that they may have and do my job properly. That was esteem building and confidence building that makes me feel like I have something to offer and that's all attributed back to the program itself. It's the whole attitude towards making everyone be counted. No one is excluded, it's really amazing. That's just an amazing thing so that's down to this public library, to San Francisco's library that they really wanted to address this issue as one library and not make it be separate. So it's not like how can we get this out? It's like how can we incorporate this in? That's really phenomenal and that's on this side of it and on the other side of the same coin is me and how they incorporated me into that same picture and allowed me to take the seed planted here and take it as far as I wish to take it. That's mind boggling. Who does that? Who does that? It's really quite amazing. It's a star, definitely a star.


There'll be a huge amount of uncertainty and the Europeans will have to figure out whether they want to go towards more integration of Europe and more integration of the Eurozone, even if the voters are becoming increasingly skeptical about giving power to Brussels in the center, or whether there'll be more variable geometry and less autonomy of nations within Europe and the Eurozone, but then having less of an integration that might be needed to have a completely monetary union. I think these sets of economic and political uncertainty are going to bear on economic growth, are going to bear down on financial asset prices, and are going to create a significant amount of uncertainty.


But to Maine we go, where Liam, our colleague, has written about an abortion rights amendment. This is popping up in Florida now. I think Arizona is going to see it. I think several states are trying to introduce and codify abortion into their constitutions now that it's a state-by-state issue, but it didn't work in Maine. Yeah. Several states have done so. There was an amendment in Kansas, in California, in New York, in Ohio. And this is something that we're starting to see pro-abortion advocates do because abortion is no longer a protected constitutional right under Roe v. Wade because of the recent decision. States are resorting to this tactic in Maine as the most recent one to do so. There was a proposed amendment that if pass would have codified abortion rights since the state constitution, it was a bill as proposed as a bill. And if the bill was to be passed, it would have sent a referendum to the citizens of Maine to vote on in November's election.


The Independent National Electoral Commission, INEC, has blamed its failure to persecute electoral offenders on the inability of the National Assembly to pass the National Electoral Offences Commission Bill 2022. This is coming as suspected arsonist raises another office of the electoral body in all the local government area of Emma State. The chairman of INEC, Professor Mahmood Yokubu, made a clarification at a one-day strategic interactive meeting with line editors. He called on the federal legislator to expedite action on the passage of the National Electoral Offences Commission Bill. Consistently, since 2009, committees set up on electoral reform have recommended that there should be an Electoral Offences Commission and Tribunal, to which all violators of Electoral Commission will be subjected. Ways recommended in 2009, the Lemu Committee, after the 2011 post-election violence and in 2017, the Ken Namani Committee made the same recommendation. Why is it that we have not as a nation established the Electoral Offences Commission and Tribunal? But happily, happily, the Senate through private members bills are proposed and the proposal has gone through fast and secure reading, who are invited to the public hearing. We supported it and not too long ago, the House of Representatives, who are waiting for the concurrence of the two chambers of the National Assembly to establish this Electoral Offences Commission and Tribunal. We leave the commission of this responsibility and this will lead to speedier, in our view, speedier prosecution of Electoral Offences. So may I seize this opportunity to once again appeal to the National Assembly for expeditious consideration of the bill so that this commission will be established as soon as possible.


Hi everyone happy Thursday and happy the first of the month first of the month September Alrighty man first break September. It's going to be 2015 Panini Donner's baseball Hobby pack number five. This is the last filler. We got to do to unlock that diamond icon baseball We're giving away the final three random number block spots That's coming up in the next video and the next video after that will be that break and then we'll probably put that into Another filler so if you want to grab your teams right now Get those get those before they end up in some sort of filler big thanks to this group here for making it happen Appreciate it, and there's all the baseball teams right there I think I've got all the names right in here. Yeah So we'll do the pack break first and then the second dice will be the giveaway part But for the pack break four and a five nine times one two three four Five and a ninth in final time got Kenneth down to Russell and After nine times of teams one two nine final time No trade windows here as well not for these little filler breaks I guess it's a new month. So let's show you use a different font here What do I like? We're gonna do we usually trade off serif and sans serif We'll go to the sans serif font kind of like leto I don't know how much difference that makes but Kind of like that. It looks pretty good. It's a little change on the usual aerial All right, Calibri. I think we've used Calibri before Calibri Leto is a little bit bigger than Calibri at the 12 point font Kind of like the bigger size Leto is your September font for font fans out there for a typologists who love the typography Design fans all the Calibri might save us a little bit on on toner Leto it is we live in excess. Let's see what we got here in the 2015 Darvish to 299 a numbered card to Naka and Christian Walker the rookies and all the money we save on Calibri. We can pay you in break credit Probably probably adds up pennies on the day. I'm sure All right, so nothing too great is here that you Darvish is Rangers edition So that's gonna go to that card will go to Rex. Let's gather everybody's names here second and final dice roll and the top three After Six and a four ten times one two three four five six seven eight nine and 10th and final time Six and a four so after ten times a lot of sad faces Especially Nestor a very close Nestor, but not quite But four through 30 sad times Thankfully this filler was kind of cheap. I think it wasn't very much right Maybe 14 15 bucks a spot anyhow. Thanks for taking the risk boys and girls Top three though happy times for you. You are in that random number block randomizer in the next stage Kenneth is happy Nestor we got you in there Michael locia in as well. Congrats. You three. We'll see you the next video Jasper's case breaks calm


All right. Let's get started. All right, so we have two new topics for today. Quiet please. So two new topics for today. The first one is programming languages and how they support concurrency. And the second one is deadlocks, which are a very important class of concurrency problems to understand and try to prevent. So we'll start off by reviewing the main topic from last time, which was the reader's writer's design. And then we'll go through some of the common programming languages and how they support synchronization. And then finally, we'll talk about contention for resources and how it can lead to deadlock and how to recognize that and hopefully avoid it. So from last time, we looked at the reader's writer's problem and the model is to consider some kind of shared writable storage like a database and users that are trying to read and write from that store. So the readers don't change what's in the store. So multiple readers can access it at the same time. The writer, since they're modifying the content, we want to give them exclusive access. So question is, is single lock on the database sufficient? It wasn't the model we looked at last time. We wanted to basically do something a little bit more complicated that would allow many readers at the same time and only one writer. So the correctness constraints were readers can access the database when there are no writers. Writers can access when there's nobody, neither reader nor writer. Only one thread, only one writer should be manipulating the state variables, whether they're a reader or a writer. Okay, so here's the basic structure of a solution. Here's the reader piece. So the reader waits until there are no writers, accesses the database and then checks out. The writer is waiting until basically nobody else is trying to access, accesses the database and checks out. So that's the high order and the only sort of tweak to that is to give writers a bit of an extra priority. So in order to manage the access, we keep track of the state of the readers and writers using these state variables. The count of active readers, the count of waiting readers and similarly active writers and waiting writers. And we have some condition variables as well. Here's the reader code again. All right, so we saw this last time and at high level we're using the locks to manage access to these state variables but we're actually releasing the lock before we access the database. Then re-acquiring it afterwards, changing some of the state variables and then releasing again. Why do we do that? Someone quickly remind us why we did it that way. Well, it's not really a Mesa versus a whore monitor question, it's a question about allowing access, allowing the other threads to figure out what's happening. So it makes sense, so what we're actually locking here is the state variables. So we want to allow a reader to go and endure a read and another reader to actually get through here and do a read at the same time. What's that? Yeah, exactly, the database is not changing so we don't need to lock it. And specifically we want to allow other readers to get through all of this stuff without getting stuck. So we want to synchronously update the state of readers and writers, all right? So we may have updated a writer, sorry, excuse me. We may have updated some state here but we want to allow the other readers to go through and check and possibly wait if they need to but if they don't need to wait, we want to give them access to the database. All right, so writer code is kind of similar. You know, we went in detail into all of these conditions last time so I won't revisit that but at high level we have a similar pattern which is, you know, the writers come in. In this case though, there's a big difference between last time, between this time and last time which is what happens to a second writer here. What's gonna happen when a second writer comes in? Yeah, right, if there's somebody actively writing this variable is gonna be greater than zero so this test is going to succeed which will keep you in the loop and will keep you waiting until somebody signals you that that resource is free. All right, so this is protecting access to these state variables but still allowing a writer through, in this case only the first one and once they go through and update the number of active writers at the end, decreasing that then that will allow other writers through. All right, so let's see. All right, okay, so we had some detailed discussion of broadcast and signal at the end. Why do we broadcast? So what's happening down here, let's see. We have, if we have waiting writers greater than zero, yeah, yes, yeah, we wanna let all of the potentially waiting writers and readers know that the state is now accessible and we first checked actually if there are waiting writers and signal those first actually, why do we do that? Yeah, intuitively you wanna give writers priority in case they're ready to do an update to the data so you'd rather that happen first before somebody reading the data and getting stale data although they could get more up-to-date data, right? So that priority is important. All right, so next topic is language support for synchronization. So locks have been in the C language since the beginning and a lock in C is a very simple object. You can acquire it and release it and that means that, excuse me, you're responsible for taking care of all of the exceptional conditions that might occur. So that typically doesn't involve throwing exceptions, they're not part of the language by default so you have to test error conditions, explicitly release the lock and then return an error code. So it's not completely trivial in a complex program but it's somewhat tractable because you can eyeball the code and try to figure out all the code paths and make sure there's no exit from the SQL to a lock that might escape without unlocking. C++ is more challenging because you do have exceptions in the language. So exceptions create a lot of new exit paths because you can throw an exception potentially anywhere in the code. So, all right, so yeah, here's a little routine, acquires a lock, this function here can throw an exception somewhere in its body, that will actually skip past the code that's following it in the block there and basically leave the lock still locked. So that's very dangerous, all right. So there are a couple of ways of dealing with this. One way is sort of following the C design which is to try to catch, to try to find all the code paths that can exit which would include exceptional exits. So that requires you to catch the exception that might be thrown and then release the lock and then also have a lock release in the normal code path.  It's certainly better than not catching the exception. One gnarly issue with C++ is it doesn't have an ancestor exception class that basically specializes to all the exceptions. So there's no way to catch a universal exception object here. And this piece of syntax is literally three dots. It's not a placeholder for something. It means catch anything, it's a specific piece of syntax. But since it doesn't know the type of that thing, you don't actually get a handle on the thing that's being thrown. So it does allow you to release the lock. On the other hand, when you throw, you're gonna throw an unknown exception. So this is kind of bad because it loses the state that you had about what was wrong. So there's a different approach which is recommended by Jan Stroustrop which is using the support that's built into the language for unwinding the stack when there is an exception. So in C++ you have constructors and destructors for objects. And for variables that are allocated on the stack for automatic variables, the constructor is called when the variable is created and the destructor is called when you exit from that block or stack frame. So that allows you to let the unwinding code within C++ deal with locks. So a recommended motif is to have a sort of a primitive mutex object here, and underline and then create a constructor method for the lock class. This is a constructor which basically initializes its internal reference variable to some explicitly created lock, then acquires it and finally in the destructor releases it. So you're relying on the fact that that destructor is called automatically. So now if you wanna protect some code in here, this is a local variable declaration. It creates an automatic variable that's on the stack. And that variable is automatically cleared off the stack. The whole stack frame is cleared and the destructor is called at that time. So that will automatically release the lock. And the unwinding and the destructor is gonna be called whether that's a normal exit or an exceptional exit. So if an exception's thrown, the exception handler is gonna unwind every stack frame and if there's anything allocated in any of those frames it frees it or it calls its destructor. So any locks that are along that path will be cleared. Yeah, question? Well, it's gonna be called whenever the variable for an automatic variable, whenever the variable goes out of is basically destroyed which means going out of scope for a block scoped variable like this one. So the critical section here is, so you can put a block anywhere in code just in closing it with parentheses. And for the instructions in there, any variables declared inside of the block are in scope but as soon as you leave the scope it has to destroy everything that was in that scope. Yeah, oh, I see if you, well that's a good question. All right, so if you have code that's possibly involving the objects that you're trying to protect in the destructors. Yeah, I think, yeah, I think you can go wrong but normally you would be doing explicit manipulation of the object state in here and then in a certain sense the destructors are being called right there. You know, the obvious thing is not to put code in the destructors that's manipulating those, you know, what should be protected variables. I think it should be fine. All right, so in Java actually there's two really different families of synchronization primitives, both low level and high level ones. And the low level ones look like the ones we've seen so far. We have basically a lock class, supports locking and unlocking and we have conditioned variables that support waiting which is called await and signaling through a signal method. So these really are very similar to what we've seen so far. The new set of primitives are the synchronized primitives, synchronized keyword and the corresponding, so the new primitives involve implicit locks and implicit conditioned variables. One of each of which is associated with every object in Java. So those allow you to basically apply a lock that applies to one object while you manipulate the object and have it automatically be released when you exit a code block. Similarly, there are conditioned variables which are accessed through wait and notify methods that are implicitly attached to the object that's currently holding the lock. So these work apparently without any explicit connection between them. The connections are all implicit. It sounds complicated, but it's usually intuitive and very simple. All right, so let's look quickly at a synchronized queue using the explicit synchronization primitives in Java. So first of all, we create a lock. We use a re-entrant lock class most of the time that's what you want. Non-re-entrant locks are usually a really bad idea. And we can create a conditioned variable that you notice is being called as a method call on the lock. So in this way, the conditioned variables associated with a monitor which is basically the lock. All right, so, and then finally, there's some internal state which in this case is a linked list of integers. So the enqueuing pattern should look pretty familiar. We want to first of all acquire a lock, add an item to the queue, and then go to sleep. And basically signal anyone that might already be waiting to see if there's an item in the queue. And we have a nice extra feature in Java which is a finally keyword which substitutes for normal and abnormal exits from a try block. So if the code executes normally here, we're gonna pass into the finally block. If the code has an exception somewhere, it's also caught by the finally block. And this is executed. So finally gets executed always, including if there was an explicit catch in there, the catch would get executed if it did catch the exception, but the finally block would also get executed. So it provides a fail-safe guarantee that that lock's gonna get released. On the other end, when we dequeue an item, let's see. So again, we first of all check if the item is, sorry, we check if the queue is empty or not, acquire the lock first, check if the queue is empty. If it is empty, then we're gonna wait for a while until somebody signals us. Otherwise, we're gonna remove the item from the queue and finally abnormally we're gonna exit and release the lock. Yeah, that's a good question. No, maybe it's too much detail, do you think? Or, so yeah, a little bit too much detail for DesignDoc. All right, so that's the low-level version of synchronization in Java. Java also has high-level synchronization. In fact, Java had high-level synchronization primitives before the low-level ones were added. And Java generally, if you don't know, was a language that was entirely motivated by the idea of avoiding common programmer errors. So the developers of Java looked at the most common errors that programmers made in languages like C++ and tried to engineer the language to avoid them. And initially, they only supported implicit locks and condition variables. And they're following very much the KISS principle. So what is the KISS principle, somebody? Keep it simple, student. In this class, it's keep it simple student. All right, so we wanna make sure that the code is easy to understand by looking at it and we wanna minimize complexity. If there's a simple way to do things, we're gonna favor that way. So there are reasons for using explicit locks, plenty of reasons, but you should have a good reason if you use them. All right, there's a real issue with code maintainability these days for a lot of projects. Last time we talked about teams and how different members of the team can contribute. Sometimes people can also play a kind of an oversight role without necessarily, or a checking role without necessarily doing the code. But coding in the large is really a many-person activity that extends across time and space, which means that often the people that are developing code never actually spoke to the original authors of the code. So again, it's important to think about lifetime and complexity. So what is the typical lifetime of a piece of code? It's a lot bigger than most people think. If you look at most pieces of software, most of the open source projects, it's in the decades. And that's a lot longer than the original developers anticipated. The developers of the operating system, Mark, who were working in the 90s probably didn't think they were programming for iPhone, program the operating system of iPhones or Macs. But that's what happens. So anyway, so it's important to anticipate and try to minimize complexity and try to be explicit about assumptions that you're making. It's interesting to look at concurrency bugs. So I'm briefly gonna mention some things that people have observed about concurrency bugs. So one thing is that concurrency bugs seem to be one of three main types. The most common type is atomicity violations, which means not protecting some resource that should be protected. The second group is order violations, doing things out of order, perhaps reading, perhaps not waiting for something to be ready before you try to access it. And we already saw a number of order constraints in several of the pieces of code that we looked at. But in general, they're quite complex. The last one is deadlocks, which we're gonna look at in detail in the second half of this lecture. So that's what people run into. And it's interesting that there's a sort of a duality between the type one and the type three. So atomicity means sequences of steps that should be atomic that need to be executed together for correctness and not being executed together. So you're in a sense under protecting. Perhaps there's a critical section that's too small or there's protection that's missing entirely. Type three on the other hand is a kind of a deadlocks, as we'll see often result from over-protecting, reserving too many resources or locking too much code, causing resources to become unavailable to other threads and leading to eventually to a deadlock problem. And unfortunately, people have found that fixes to deadlock problems are often involved creating atomicity problems because people see a deadlock and they start trying to release and back off the locks and end up actually exposing further problems. The good news is that most non-deadlock bugs involve only one variable, surprisingly. And 90% of the deadlock problems involve only two threads and two resources. And some deadlocks involve only one resource and one thread. And I'm gonna come back to that because it's very counter-intuitive but it's actually simple to fix but it's a problem that shows up often. All right, and finally, some not so good news. Can currency bugs seem to be a small fraction of all reported bugs, maybe about 3% but consume a large fraction of debugging time, perhaps closer to 30% and the typical time to fix bugs is in the days instead of hours. So all of this is part of hopefully strong motivation for you to be careful about using concurrency, make the uses of concurrency as transparent as simple as you can. All right, so let's look now at the high level primitives that Java provides and we'll rely on the fact that objects in Java without any action by the programmer have associated implicit locks with them. So every object has a single lock that is locked implicitly when you use a synchronized block or method. And the example's on the next slide. So synchronized, the synchronized keywords acquires a lock and releases a lock around some section that's protected by the synchronized keyword. So for a synchronized method if you put synchronized in the preamble of a method declaration here, then basically everything in the method is synchronized by the implicit lock associated with the main class, an instance of the main class. So in other words, it's this object if you wanted to think of it in terms of language. So the locks are quiet at the start of the method released at the end. You don't have to worry about naming it though. It's always the one that's implicitly associated with this. The block-structured version of synchronized is a block that can occur anywhere in a routine and it involves the implicit lock associated with a different object. So that can be any instance of a class in Java and you basically acquire a lock on its implicit lock at the beginning of the code and then you exit it automatically at the end. Again, it'll take care of exceptions if an exception arises in that block. So a consequence of this construction is if you wanted to replicate a synchronized method using the synchronized primitive, it's essentially the same as putting synchronized of this right at the start of the method declaration and the closing parenthesis right before the method executes. Okay, is that clear? Yeah. Well, it's locking an implicit lock on the object. So if every method is synchronized, then only one method's going to be able to access the object. But yeah. Well, the non-synchronized method can access the object. It doesn't, yeah, it'll just go straight through, yeah. So if you wanna implement a monitor, you're supposed to synchronize every method to make sure that only one method's executing at a time. Yeah. No, it's not an issue. Java doesn't have pointers, but it has references and it's normally passing references to objects. So the same bank instance, if you take the variable of type bank and you copy it somewhere or pass it to a routine, the two different contexts have the same reference, the same object, the same lock. Yeah, it'll be the same. Yeah. All right, yeah, all right. And so Java, the virtual machine's taking care of allocating and releasing the lock on normal and abnormal exits, which is very nice. Okay. All right, so in addition to the implicit lock, there's a single associated implicit condition variable associated with it. And that allows you to implement waiting and signaling or notifying very easily. There's three versions. There's a wait with no arguments and a wait with a timeout and even a wait with both a millisecond and a nanosecond parameter for the timeout. So they're probably completely meaningless in most runtime environments. But what the timeout does is cause the method to wait, but then wake up after the timeout. So it'll wake up either when it's notified or if the timeout expires. Just in case you're, you know, if you're not completely confident that something's gonna signal it to wake up, it will wake up by itself. Okay, the signaling function on the implicit condition variable is called notify. And there's a corresponding broadcast version which is notify all which will wake up all of the waiting threads on that condition variable. All right. Yeah, and so, you know, among the uses of the timeouts are dealing with exceptions that might kill the signaler. And if it does, then you can still, the correctly running threads will continue via the timeout. Okay. So some gnarly issues with this is that the VMs are not very consistent in Java. Most elements of Java are extremely stringently compliant with the standard, but scheduling is not, unfortunately, because for efficiency reasons, it tends to inherit the scheduling framework of the operating system. And some versions of Java virtual machine, the ones on Solaris, for instance, for instance, don't have preemption. So you have to be very careful in terms of threads sometimes becoming starved, essentially, not being able to run, even though in principle they could. Okay. So using the high-level primitives, the synchronized queue is quite a bit simpler. So this is the whole thing now. We have, by wrapping the synchronized keyword around the enqueue function, the locks both acquired and then released at the end of the routine, we can notify other threads when we add something in case they're waiting for the queue to become non-empty. The other synchronized queue wraps dequeue. We again wait to see if there's something ready to be read, if not, we wait. And we finally remove it. We have to catch an exception here, and we actually, this time, catch it and just return a kind of an error code, return a valid value in case the interception, in case the routine is interrupted. So any other exception is going to be automatically caught outside of here and it will cause that lock to be released again. All right, well anyway, so this version's a lot simpler. And the last thing I'll talk about briefly is a programming metaphor, a paradigm that's showing up in some newer languages that avoid synchronization issues entirely called actors. And it's in the Scala language, for instance, which is a newer functional language that uses the Java virtual machine. It's a very interesting compromise between new languages with very little library support and more conservative languages like Java. But anyway, actors are a perhaps elegant, high level abstraction for concurrent programming. So far we've been struggling with concurrency issues that are caused conceptually because we have different threads that are trying to concurrently access different objects with state in an object-oriented framework. So if these are the objects in yellow and these are some methods of each object, in concurrent programming we allow many threads potentially to access the methods and modify the state of these variables in more or less any fashion. And in order to enforce consistency we have to do synchronization. So Scala avoids that by associating the program or process activity with each significant block of state, so each actor now is going up from Java objects to actors. Each object has a single thread and in fact there's only ever one thread running the code inside of an actor so there's no concurrency issue. And actors interact by sending and receiving messages normally without any notion of blocking. And in fact, rather than function calling it's a message passing paradigm which means when you ask something to happen if you want a return value you actually have to wait for and receive a return message. So the main functional part of an actor is a loop which is sending and receiving messages and synchronization is happening invisibly in the implementation of the while loop which basically has a synchronous queue. So all actors can pass messages to each other through those synchronized queues without the programmer having to worry about it. So it allows you to create some simple, well, simple programs to do fairly complicated things. So here's an actor that implements a bank statement that allows you to do deposits, withdrawals, calculating interest, computing a balance, has a single internal variable and you send messages to it to basically cause these things to happen. And here's a simple actor that also this is the message passing syntax here. It sends a message to the main bank account asking it to add a certain amount of interest. So, and that sleeps for a while. So this program basically creates an account and updates it periodically. And you notice there's no synchronization even though there is shared state which can be accessed by many different actors but the message queues guarantee that it's consistent. So anyway, it's worth knowing there's, so actors can't do everything but they are an interesting paradigm that's seeing increasing use in industry for concurrent programming. All right, so all right, we're gonna move on now to deadlock, are there any questions about the programming paradigms? All right, so now let's look at contention and deadlock and what we can do about it. So resources, they're the passive entities that programs use in order to function. Things like disk drives, IO devices, memory and so on. And they come in two flavors, the preemptible resources, commonly the CPU which can be scheduled and there are non-preemptible resources such as disk space, printers and so on which normally only one process that's accessed to at a time. And so resources may or may not require exclusive access from the processes or they may be shareable. So read-only objects are typically shareable and objects who state you're modifying such as printers are normally not shareable. All right, and the operating system has a duty of managing access to and protecting the resources. Across users. Okay, so there's two ways to get into trouble with multiple threads running. The first of them is starvation where threads are waiting and for some reason unable to run. So starvation is a simpler problem where threads may not be able to run because they lack priority. Sometimes because, well, if the operating system's not preemptive, they may also be stuck because nobody's given up control. Deadlocks are a more serious problem which is that threads end up waiting on resources that they can't access because some other thread has reserved them and is not gonna give them up. It inevitably involves some kind of cycle and normally at least two resources although people have managed to find ways to deadlock with one resource and one thread. Normally involves at least two though. And the resource is owned by one thread which is waiting for a second resource which is owned by another thread which is waiting for the first resource. So it's a surprisingly common problem as you saw in that list of top concurrency bugs. It's one of the top three. So deadlock implies starvation. It implies that certain threads are unable to run but not vice versa. And starvation can end in a variety of ways sometimes changing a scheduling policy but deadlock cannot change unless there's some more drastic external interventions such as killing one of the threads. Okay. Very often probably, well actually probably almost always deadlock is non-deterministic and it requires specific timing in the acquisition of resources. And we saw an example of this before actually when we were discussing semaphores for the first time. If you recall, P is the probe function which decrements the resource and weights if it's zero and V is the increment function. And if you put these out of order and if in addition they execute in the wrong order you get a deadlock. So basically A is grabbing the first mutex, B is grabbing the second one, now A can't acquire the second one and B can't acquire the first one. So you get the loop structure that we just saw. On the other hand, if thread B is able to execute a little bit faster than thread A and acquire both resources, then it just runs to conclusion and then thread A will start. And in fact, there's multiple ways in which this can evolve. All right, so because of this dependence of multiple resources there's often not a simple way to sort of break the problem down and solve it separately. You have to deal with the whole cyclic structure of the deadlock. So intuitively we can use a couple of metaphors for this. Deadlock is very similar to gridlock on a highway or a freeway. So gridlock arises when you get different vehicles trying to use the same piece of road at the same time and there's not enough road for the people like a one-way bridge is an example. So in that case you have to resolve the deadlock by somebody giving up the resource that they've partially acquired. So a more realistic example comes from routing on multi-core processors. In a multi-core processor you have some kind of physical wired interconnect network and you try to route messages from one processor to another and you want that routing to be extremely fast, meaning you wanna basically get a wired connection from the source to the destination without buffering in the middle. So somehow that requires you, if you wanna send from here to here you have to reserve both the wires along the way. And as you can see from this picture it's potentially very easy to get gridlock. In fact with a hardware processor where things are happening on a very tight schedule deadlock's very likely because each core here might first reserve the first link that it needs to get to its destination. And so you'd have a synchronous acquisition of the very first resource and then when you try to get the second one you'll get a deadlock. So sorry we'll come back to that one later but you can see that there's a real potential of deadlock here. Another situation that Amore perhaps a more humorous version of this situation is the dining philosophers problem. So in this situation you imagine five philosophers sitting down at a table in a Chinese restaurant and there are only five chopsticks. And each philosopher intuitively grabs for two chopsticks but in the worst case only acquires one of them. Say the left one. So again you get the cycle of each actor owning one resource and trying to acquire another one. All right so those examples give us some of the elements of deadlock so let's try to define them more precisely. The first requirement is that there's some kind of mutual exclusion in operation. So the resources are such that only one of the processes can use them at a given time. And secondly there's at least there are several hold and wait states where one process is holding some resource and trying to acquire another. The holding is preventing some other process from acquiring that resource and the wait is causing that process to stall and not continue and potentially blocking other actors that are trying to acquire its own resource. And sorry a third criterion is that there's no preemption meaning that all of the actors along this chain have the same priority. So in other words an actor can't simply grab a resource that some other actor is holding because that would break this cycle. So there's an assumption that nobody is getting priority and able to sort of break the cycle and move ahead. And the last condition is that there should be a circular weight. So sorry we have a thread T1 that's waiting for a resource that's held by T2 and then another thread T2 that's waiting for a resource held by T3 and so on. The last thread is holding resource that's held by T1. So that cycle is propagating this waiting action back and back and back and all the way around in the cycle. All right, so we can analyze the situation a little bit more generally using a resource allocation graph. So in the resource allocation graph we have a set of threads T1 through TN and a set of resource types R1 through RM. And for each resource type we can have multiple instances of the resource. So the instances are shown inside of the square blocks there. So there's three instances of resource type R2 and one instance of resource type R1. And the threads are going to request and then use and then release their resources in some fashion. And we can represent all of those actions by the threads using a graph. All right, and so again this entire set of objects is partitioned into the threads and the resources. And we have a graph between these objects from threads to resources which are the request edges and then assignment edge is going back from resources to threads. So a request arrow means that this threads trying to acquire resource RJ and the assignment edge says that RJ is already owned by the thread. Okay, so here's an example resource allocation graph. All right, so what does this mean? So this arrow here means that this resource is held by T2, T1 is requesting that resource. Here we've got two instances of resource type R3 being held by two different threads. So is there any deadlock there, anybody? There's sort of a cycle, but is it a problem? Well there is an undirected cycle, is that a problem? Well which of these threads is waiting on something? Well T2 is potentially waiting on T1, right? Because T1 is currently listed as the owner of that resource, but on the other hand T1's waiting on, well it's only uniquely assigned to that instance of resource R3. So it's not really waiting, it can just grab R3 and run and finish. So a requirement of the deadlock is that the cycle should be directed so that every thread's being blocked by something. This thread's not being blocked by any other thread. All right, and what about this one? This is, all right. Who thinks there's a cycle here, is a directed cycle here, right? If I take this arrow away, there's a directed cycle. But is it deadlock? All right, I heard a yes, go ahead, right, right. Yeah, potentially, yeah, there's two instances of R3, so in fact, actually it's somewhat complicated, but yeah, it's not a clear deadlock. Depending on the order in which things happen, if T2 or T1 is able to execute, it basically clears the cycle and this process can continue. All right, and actually no, I'm sorry, I got this wrong. There is a problem here because of that, yeah, there is a directed cycle. Everything is basically pinned by a preceding processor, sorry about that. Here we have the cycle that doesn't comprise deadlock because this second resource is actually consumed by T4. So, all right, sorry about that. Take a quick look at this and I'll try to work through this a bit more carefully. So the trouble here is that these two resources are potentially, one of these is owned by T3 so there's potentially a cycle through there, which can cause deadlock. Any questions? So we're gonna, rather than going through this example, we're gonna do an algorithm for detecting deadlock so I think we should probably wait till that. All right, let me see. So request edge is a directed edge from T1. All right, so T1 is requesting R3. Yeah, you're right actually. All right, so T1 is requesting R3. And yeah, all right, thank you. So that makes it clearer. So yeah, T1 is requesting R3 and both instances of the R3 resource are being held by different processes. All right, so yeah, good comment. All right, so yeah, it is actually, it's much simpler to explain now because yeah, we see these two resources being held here. This T1 here is trying to acquire one which is being held by T2 and so on. All right, so that's where the cycle comes in. All right, so, okay, so we are gonna go through and do a fairly careful procedure for detecting deadlock which will solve this case and other cases. So, some administrative here, the project one design documents are due tomorrow at one minute before midnight so there's no slip days on the project design documents and it's helpful if you post anonymously to post non-anonymously to Piazzo. You can post anonymously if you want to but it helps us to understand your issues if you get posted non-anonymously and it also allows you to get credit for class participation in Piazzo. So it's better if you can do that. Well if you, yeah, all right. So all right, well, so I assume that you could create a pseudonym if you wanted to but all right, so let's take a five minute break and we'll finish up and look at the some deadlock detection algorithms. All right, let's get started again. So I'm gonna try to get through the rest of the material quickly so let's just try to stay in sync and see what we can do. So there are several methods for handling deadlock. A simple method is just let it happen and try to recover. So that assumes that you have a way of detecting deadlock and once threads become locked that's usually straightforward. Finding a cycle of circular weights is fairly easy. There's a Java call that you can use within a program or if you want JVisualVM which is a utility that's in the JDK, does anyone run that? It's very useful for profiling but among other things it allows you to examine the threads in a live running program without the overhead that you get with using the debugger which sometimes causes strange deadlock situations not to happen. So you can wait for deadlock and then examine the deadlock using this routine. You can forcibly preempt resources once you recognize it. There are a variety of deadlock prevention systems that attempt to make sure that deadlock just doesn't happen. Those typically involve monitoring resource requests i.e. lock acquisitions and deny those in case they might lead to deadlock. And finally you can ignore the problem and just allow the programmer to try to deal with it and that's the approach taken in UNIX. All right so you can look for a simple cyclic loops on individual resources, a more general deadlock detection algorithm use sets of resources and so we assume that we have a vector x of numbers of resources of each type. So free resources x is a vector of those numbers. A request is a vector of requests, again a number of objects that you're requesting of each type and finally the allocation is the number of objects of each type that you're allocated currently. So here we have two resources and I guess four threads so you'd have a vector of length two with account of the number of resources of each type that you are trying to acquire. And the routine basically tries to simulate those threads acquiring and then releasing the resources in some order and if you can find an ordering in which everything holds it determines that there isn't deadlock because if there is an ordering the threads themselves will find it by executing. So the basic cycle is for every node that hasn't yet finished look at their request see if it's less than or equal to the available resources at that time. If it is you simulate them accumulating the resources and then releasing them. So you remove that node from the list of unfinished nodes increment the set of available resources by what you had allocated that to that node. So that's simulating releasing those resources. And you set a flag to say that you're not done yet but you basically go back to the do loop and reset that flag done flag is just testing if there's any work to do in the unfinished list. Okay, so once there's nothing left in the unfinished list if you weren't I'm sorry if you exit with the unfinished list not empty that means that there were some nodes that weren't able to acquire their resources therefore you have deadlock. All right, so here's our collection of objects again. So there are two resources. So each vector is a vector of two elements. So this is the count of resource number one that thread one is requesting and this is the count of resource number two that thread one is requesting. All right, and in the beginning we've allocated thread T one one copy of resource number two. So that's the arrow there. So in other words, this arrow is the allocation and this request is the request vector there. All right, and similar the other arrows are represented in these request and allocation vectors. Available resources is zero because you can see all of their resource instances are currently held by something and unfinished basically everything's running currently none of the threads have finished executing. So we can simulate by working through this routine the request. So we pick a node which is gonna be unfinished so we'll get T one first. T one's request here one zero. Is it less than the available resources? Well, there's nothing actually available right now. So that's gonna fail and we'll skip to the next node. Okay, so it's gonna be T two. T two's requesting nothing. So that actually is less than the available request. So T two, in other words, T two has this resource here. So it's able to run and finish and depart from the queue. And as it does that it's gonna free up its currently allocated resources here. So a lot T two is one zero. Those go back into the available list there and we continue. So T two is out of the picture. We're gonna look at the next node which is T three. T three is requesting an instance of R two and R two is not currently available. So we'll go back and try again. We'll try T four. And anyway, you get the idea. T two, T four is not requesting anything. It already has its resource. So it's gonna depart from the picture. And similarly, as we continue through back to T one, it has the resource that it needs. So it's gonna exit the picture. Finally, we're gonna get back to T three which had the resource that needed and it's gonna exit. So through the simulation, we were able to show that all of the threads were able to get their resources and finish. And in the process, free them up for other threads. And that's how this whole process, the whole picture was able to clear. Okay, so any questions about that algorithm? So it's an effect of simulation of the whole process of threads acquiring resources. We're not guaranteeing that things happen in the same order. But what we're showing is that there's some order for which the processes can acquire what they need in complete. And if that's true, then they won't be deadlocked. All right, so what about some techniques for preventing deadlock? One approach is to somehow present very large numbers of copies of the resources. So for instance, most operating systems give you a huge number of file handles. Any kind of object that's cheap, that consumes a small amount of real resources is easy to make close to infinite. And that will often prevent deadlock situations by basically always allowing threads to acquire more instances of each type. But of course, things like printers, you can't do that. Things like routing paths on a multiprocessor network, you can't do that with. You could require that there's no sharing of resources. Something like that is done in the active framework. But there are some pretty severe restrictions of that. We talked about that earlier in the class. Another approach, maybe that's more promising, is by not allowing waiting, perhaps having a return message or callback approach that basically stops the caller from blocking and just waiting for the resource and allows them to do other work. So that actually is a more realistic approach. But again, it doesn't work for everything. So, and as we drill down a little bit, there are also techniques that are closer to that simulation of resource acquisition that we can use dynamically to predict if deadlock can occur and again prevent acquisition of resources that might lead to deadlock before it happens. So here's an extreme example is deciding not to leave home because anyone might be on the highways and freeways and therefore might cause you to be prevented from going where you wanna go. That's far too conservative. A realistic approach that is actually used is ordering the priority of requests. So we already argued that in order to have gridlock, we have to have a circular sequence of dependencies with no preemption and if you enforce a certain type of ordering, you can prevent those cycles. So a simple way is to use geometry because cycles, for instance, on the processor grid have X and Y orientations. So let's go back to that problem. So again, the problem was to deal with the circular dependency of resource allocation where we have say four processors that are trying to route some streams of bits around the multi-processor grid connection network and each processor is trying to communicate with the processor around the corner. So they require two links to stream the bits around but you've got four processors each requesting two links in this example and with a simple synchronous request policy where each node requests the first link first, you can see that you get a deadlock situation here which is like gridlock. So the solution is to use a dimension ordering because in a geometric cycle like this, there have to be X links and Y links. Dimension ordering gives priority to one of the directions, typically the X direction and says, all right, this request here is starting with an X route first. It's now requesting the Y route but the initial request was for X and therefore the second request will actually preempt the guy that's holding the second link here. So the first request is getting both links because their initial direction was in X. Similarly for the request down here, this request from the corner guy here preempts this other guy and so you get two of the nodes getting their entire path as a result of preemption. So that allows those two nodes, the two corner nodes to route their packets through the network. When they're finished, the other two nodes can get their request fulfilled and route. So that's an example of X, Y routing and people have realized that actually this is a constraint on the turning directions and it's often expressed in terms of east to south turns or west to north turns and you can actually use the turn direction as a constraint and basically give priority to these turns over these ones. So all right, so any questions about the routing preemption? Yeah, no, I think that's a very good comment. I mean, yes, you essentially have to have an a priori knowledge of what the requests might be in some way of creating a total order on them which can be quite hard, yeah. Yeah, yeah, if it's a store and forward network that's not too bad, although the cost of buffering here is very high and but for a process of switching network you're trying to get these packets across extremely fast and if you have to buffer your doubling the time. In fact, this processor, it's often gonna start working on the bits before all of them have arrived for a lot of operations. So, no, this is really a switching network so you need to switch all the way through. All right, so the last topic is building on this idea for deadlock detection with multiple resources and kind of making it dynamic so that it can be used as a potential deadlock detection algorithm. So, the idea is to require a bit of extra information from the threads about what resources they might use in the worst case and then making sure that your available resources are at least enough to fulfill the requests by other threads. So, in other words, we're talking about a single thread that's trying to proceed. It requests some resources. There's a certain number of available resources and basically this test says that after you give those resources to this requesting thread, everybody else, what's left is at least enough for the largest remaining thread. Okay, all right, so that's a pretty heavy requirement. The banker's algorithm is a more modest algorithm that requires a sort of mini simulation of the style that we just did a few slides ago whenever a new request comes in. All right, so when a new request does come in, you grant it if you can find an ordering of the threads grabbing using releasing the resources that doesn't cause deadlock. So in other words, you do a full simulation of the kind that we did a few slides ago. And this guarantees that the system can't deadlock because you've proved that there's some execution of threads, the least one thread that can proceed at each step acquire what it needs run and complete. And so the threads may not do exactly that, but in the worst case, they'll do what the simulation simulates. And so it allows the maximum resource needs of all the threads to be greater than the total resources. So it's in other words, more not as conservative as the first one. All right, so before you grant the request to the thread, you pretend that it's been granted and then run the deadlock algorithm on the resulting request graph, right? So that's a piece of, this is sort of transformation we did to the previous code, but here's the routine by itself. So again, we go through each node that's not finished in the process of resource allocation graph and make sure that the maximum request of that node because we don't know what it's actually gonna request minus the current allocation is less than the available resources. All right, so this is somewhat different from what we had before where it was a static allocation graph. Here we're saying we have an upper bound on what this thread might require as it's running and we'll let it run as long as its maximum request minus what we've allocated is still gonna be available at least for some thread, okay? So it's a little bit more dynamic than the previous version. The previous version was using for this block here what each thread was actually currently using. Here we're saying we don't know what it's going to use, but as long as its maximum request minus what it currently has is within the available set of resources, then it can clearly run so we can simulate it running and remove it from the queue of things that still have to finish, free up its resources and then declare that you should continue through the loop. So in other words, it's exactly the algorithm as before except that it uses kind of an upper bound on resources instead of the actual resources allocated. All right, is that intuitive? Okay, so, all right. So applying that to the dining philosophers problem. So we recall we had five, effectively five threads and five chopsticks, we wanna allocate them. So there are some situations where we can examine what the philosophers actually did in the process and determine that we won't get deadlock. If either when somebody grabs for a chopstick, it's not the last chopstick or it is the last chopstick, but somebody will have two of them afterwards. All right? So we can let, we're not in risk of deadlock when the first few philosophers grab a chopstick. We're not in a bad situation yet. And in particular, if a certain philosopher, so we let this thing run a little bit if some philosopher grabs two chopsticks, we're actually, we're golden because they're gonna just finish and then eventually you'll get to eat, might be much later, but you know, they can complete their task, free up the resources and everything will be fine. But if let's say four of the philosophers have run grabbed a chopstick, then that's the stage where the algorithm may declare that there could be deadlock, right? Because if it is the last chopstick, then you will have a circular resource allocation graph. So the bankers algorithm will determine that you shouldn't give the last chopstick to the last philosopher if there's already a cycle or partial cycle. All right? But if it's not the last chopstick, then you keep going. So you let the algorithm run because it may all by itself avoid the deadlock. Is that intuitive? That's not a complete simulation, but it's perhaps enough of the essence of the method that you can see how it works. Yep. No, it's simulating the, I suppose the operating system, granting the resource requests.  But when you can determine that this, because you have some visibility through the resource request, the locks and the condition variables that you can determine, actually just through the locks, I'm sorry, but you can determine that there's a potential cycle and then you can stop, just avoid that allocation. That's a fair question, although I think one saving grace is, again, if you look at the empirical studies of concurrency problems, the most common problems are happening with two resources and two threads, so in which case this is probably fine. Was there another question? Yeah, no, I mean, we're giving you probably artificially complex examples. You know, the frequency of complexity of these examples goes down exponentially because it's very unusual. In the philosophers case, the probability of everybody grabbing just one chopstick at the same time is very low. If you do it, naive simulation of this kind of situation, it actually won't deadlock very often, even with sort of fairly consistent execution of all of the threads. So as the cycles become bigger, the probability of actually deadlocking them becomes quite small. So most likely in the simulation, you'll actually fairly quickly exit from the routine. Like each resource will, you'll basically determine that each thread can complete and finish, and then you're done. All right, so, okay. And the last thing is if you have, they will generalize to k-handled philosophers if that's the last chopstick, but nobody would have k of second to last and no one would have k-1. So there's a sort of a generalization of that one. All right, so let's finish because we're a little bit over time. So, all right, so we talked about, initially we talked about software support for concurrency. We spent a good amount of our time on starvation versus deadlock. Starvation means some setup where threads are waiting, but not necessarily wedged. Deadlock is a non-continuable state, requires external intervention with a circular dependency chain, requires all of these four conditions. And then we talked about ways of both detecting deadlock and then both statically, but also dynamically and hopefully potentially preventing it by not allocating resources that might lead to deadlock. And that was the bankers algorithm. All right, thank you.


My story is the story of an inner-city neighborhood that sort of adopted and helped to groom a young man who was interested in the arts and interested in making a contribution with my life and my life's work to others who were not as advantaged. So it was really a community that was economically disadvantaged and I became one of the people that helped to create a solution to a lot of the problems that people in that neighborhood were facing and I'm still doing it for a living. Way way back when I was in high school I got excited about ceramics and Carnegie Tech had a big ceramics program and I used to get a port authority bus to go out after our high school close CMU Carnegie Tech had a big ceramics program run by a guy named Wesley Mills who was an iconic figure in contemporary ceramics and helped to revitalize ceramics in the region and he really liked me and so I would sneak in to the pottery shop out at Carnegie Mellon and after a while he got aware of the fact I was doing that so he put a wedge in the door so I could get in and so I owe a lot of my early education and opportunity in clay back to Carnegie Tech. Manchester started the community of Manchester and it was during the riots and I wanted to do something to help the students in the neighborhood and I knew something about clay so I started a program called Manchester Craftsman's Guild and the idea was to take the apprentice concept and apply it to kids so that they would become in effect apprentices at the arts program and that hence Manchester Craftsman's Guild it was based on the English craft guild model and so I viewed all these students as really apprentices and I started hearing back from the school that kids were starting to show up more regularly and after a while I figured it out there wasn't anything wrong with the kids. The school system was a problem not the kids. The people who ran Bidwell it was then called the Bidwell Cultural and Training Center were looking for somebody to kind of take over the program and that turned out to be me and so I rebuilt Bidwell. It was very it was struggling and the programs were kind of dysfunctional and they owed money to the Internal Revenue Service it was it was in pretty bad shape but they had heard about my work at Manchester and offered me the job at Bidwell so I took it over and in 1972 during some very troubled times there were massive demonstrations for racial justice and the city quite literally was on fire and there were a lot of protests particularly around labor unions that wouldn't take in black people so there were massive demonstrations during that period of time whose city was in trouble. Well, Tasso Cancelos whose work I knew because he designed the chapel at St. Vincent's Monastery I just was the commencement speaker there Saturday and I found out later that Tasso had studied with Frank Lloyd Wright so I ended up at Fallingwater and I was so taken with Fallingwater I said I really want to take some of the principles in that house and basically build a school based on the principles of that house and the whole facility is light it's very bright and has a very close proximity to nature and I thought I've got to build a facility that is bright and hopeful so that people who come here whose spirit oftentimes is in the dark will come to a facility that's lit and encouraging with great food and great music and down the street we have a Hort program so flowers has now become part of our culture as well so it was all of those things that really inspired me to build this facility because I really believe that kids everybody needs to have beautiful art in their lives all the time so the best way to do it is to build a space where they see art. It has a big influence on behavior you put people in beautiful spaces they become beautiful people you put them in prisons and become prisoners. Good food, sunlight, music those are all the ingredients that you need to have present in order to get people to reimagine themselves in places and areas that their minds had never contemplated you do that by exposure it's all exposure you can't imagine it if you can't see it so what you have to do is create a picture in their heads so they can see something you know guys walk in here their eyes are open but they didn't see anything because they don't know what they're looking at but with education they begin to slowly get it that the music and the art and the food the orchids and so forth they get the idea that this is a very special place that's the whole point and that can be scaled anywhere I don't care what country it is it's I believe it's universal. The Ted people heard about me because I have a speakers bureau and called a laven agency and they were connected somehow to Ted and David said to the Ted people you got to bring this guy Bill Strickland to do a Ted talk as it turns out Herbie Hancock who had played here became a good friend and he was at Ted the Ted conference when I was there and Herbie said why don't we go out and you talk and I'll play literally no rehearsal and he went out and played the piano and I did a little slide presentation on the center and it was got a huge ovation from the audience and that that is quite literally where it started I've learned from experience keep talking just keep telling the story over and over and over again and you know once upon a time I had a one center now I got 15 right well where they come from they came from talking and so I'm gonna keep talking I'll talk to anybody that's willing to listen and do something about what they heard so it it there this is not free there was a price the price is you have to do something with what if you think I'm inspirational then do something about it and don't tell me you can't because there's got to be a homeless shelter close to where you live right help out at the homeless shelter help out with indigent kids I mean there's centers that are devoted in their lives to getting people off drugs volunteer man I don't cost you nothing in fact you may gain more than you give and I believe everybody in the if we started doing that in the world we could move this needle I'm more careful about listening because everybody's got a story everybody and I've gotten very interested in hearing those stories I mean you know you you're born everybody's born the same you're born and from there you build your story and everybody's got a journey man and I'm very interested in these journeys how people got to be what they are