Well, good morning, everybody, and welcome. And thank you very much for joining us for today's webinar. My name is Mark Fiddler, and I'll be hosting today's webinar. Joining me today, and to keep things ticking along in the background, is Deb Bond. Morning, Deb. Good morning, everyone. Deb and I are both community education officers here at the RTA, and we will take you through what we've got to discuss today. Before we do get started, I'd like to respectfully acknowledge the traditional custodians and the land on which this event is taking place, and elders past, present, and emerging. I also recognise those whose ongoing effort to protect and promote Aboriginal and Torres Strait Island cultures will leave a lasting legacy for future elders and leaders. So in today's session, we will look to cover the topics listed on the slide. We'll discuss the rights and responsibilities for both parties as listed in the act, and we will answer any questions you have as we go along. Once I have run through the topics on the screen, I'll then provide some answers to the questions that you provided when you registered, and we do thank you for those questions that has helped us put together today's webinar. We do encourage you to engage with us by dropping any questions that you do have into the live chat function as we go along, and at the end of this session today, you'll be asked to complete a short survey on this webinar, and we do encourage you to provide topics that you would like us to cover in future webinars or education sessions. So getting into it, when I proposed the topic for this webinar, we were in the middle of a long dry period, and all reports suggested that it would be, it continued throughout the summer. In some areas of Queensland, we've now had a few weeks of storms and rain, so thoughts about preparing for a dry hot summer seem a little bit distant, but whether conditions continually change, and what we're looking at at the moment is the potential of a cyclone in Northern Queensland. So again, some of the information that we will discuss today will be relevant to preparing for those sorts of events. So regardless of the conditions, there's still things that need to be considered when you're looking at your tenancy agreement and when you're putting it together. So you want to ensure that your agreement covers the condition of the property, and you also want to consider that anything that can impact the agreement, especially around weather conditions and that sort of stuff. So if your property, or if a property that you manage or that you own has gardens or lawns that require care throughout the tenancy, then it is recommended that your special term set out exactly how you expect the property to be cared for. Now when it comes to a tenant's responsibility, it's not expected that they have specialist knowledge of how to care for particular plants, hedges or gardens. So if specialist care is required, a property owner or a manager may need to consider whether you should provide a gardener or a handyman to maintain the property. In those situations, you need to ensure that the tenant is aware of any responsibilities that they may have, and even if they can meet those responsibilities. So if it's in regards to lawn care, does the tenant have a lawn mower or is one going to be provided for them? What other tools might be required that the tenant may or may not have? It's those sorts of things that you need to look at when you're setting up your tenancy agreement. The other thing I recommend is that the property owner or manager doesn't leave things to chance. So if you've got expectations on how you want things to be left at the end of the tenancy, then ensure that your special terms are clear and that your tenant does have instructions for what to do. And if there's any tenants on here today and listening on, when you're moving into a property with established lawns and gardens, make sure that you're clear about your responsibilities in looking after them. So generally, regular household jobs in the yard, such as mowing and weeding the garden, can be considered part of your obligations as a tenant. So we'd encourage you to discuss the special terms and the requirements within them at the start of the tenancy to ensure that both parties understand them before the tenancy starts. Now, just a point for those that are in rooming, accommodation or managing unit complexes, generally the lessor is responsible for maintaining the common areas. If tenants in units have a private garden or a lawn space, then we recommend that the special terms of your agreement provide details of how it should be or will be cared for. In these situations, if the lessor is arranging garden maintenance for the private garden or lawn, then entry provisions do need to be considered. And finally, what is your contingency plan? So if we do experience drought or water restrictions, is there an expectation that the tenant will need to water more or make changes? Is there an allowance for water within your special terms if they do need to water more? So communication with your tenant will be important if these circumstances occur. Now I'll touch on some of the water-charging aspects of things a little bit more in the upcoming slides. So in regards to pool care, so if a property does have a pool, there are a few things that need to be considered when you're putting together your tenancy agreement and then further expectations or considerations if we experience weather conditions or extreme weather conditions. So just as a tenant's not expected to have specialist garden knowledge or gardening knowledge, tenants renting a property with a pool are not expected to be experts at maintaining a pool. The maintenance of a pool should again be covered in the special terms of your tenancy agreement. The property manager or owner cannot enforce the tenant to engage a specific business for cleaning the pool. Generally, the tenant can be responsible for everyday tasks, such as clearing leaves from the pool and maybe responsible for basic maintenance such as filter cleaning and even checking the pH levels and the chemical levels and those sorts of things. But again, these things should be discussed with the tenant and their understanding of their requirements before signing the tenancy agreement. And ideally the property manager or owner should be providing instructions for any of the tasks that tenant must carry out. Now if pool maintenance is to be covered by a contract between the property manager or owner and an external company, then these terms should be included within the tenancy agreement. A property manager or owner cannot require the tenant to enter into a maintenance contract or require the tenant to use a particular company to provide maintenance services. It's important to remember that those things are covered under the act. Now obviously again, severe weather conditions can impact pool maintenance. And longer dry periods can lead to excessive evaporation requiring excess water use for top ups. But heavy rain periods can impact the chemical balance of the pool. So again, we recommend if these types of weather events occur then the property owner and manager should be working together to resolve any issues if the special terms haven't already covered these situations. And the last thing on pools and it's not particular to weather or maintenance but it is required that pools must be properly fenced and have a current pool safety certificate. A copy of the safety certificate should be included with the tenancy agreement. And certificates are valid for two years for non-shared pools and one year for shared pools. So when I talk about shared pools that's in situations like a unit complex and those sorts of things. Now Deb will drop a link into the chat for more information on pool safety certificates and where to find more information in regards to those things. So in regards to mould and we know that this is a topic that's very common across Queensland and a lot of our information sessions we always get questions about mould. We understand that it can occur for a variety of reasons. They can be environmental, it can be maintenance issues or it can be a lack of ventilation any of which of these can be exacerbated by weather conditions. Now who is responsible to clean it? It comes down to how and when it appeared in the first place. Now sometimes it will be clear who's responsible for example, if it's from a leaking roof and there's mould on the ceiling then we would understand that this is a maintenance issue and be up to the owner or the manager to rectify. But if there's mould in the bathroom from not using the fan or opening a window and ventilating the room properly then that could come back to the tenant's responsibility to clean and ensure that it is fixed up. Now sometimes it's no one's fault and it's purely because of the environment. Determining what's the cause of the mould may point to where the responsibility sits to rectify but it may also require the parties to work together to rectify the situation. If it's not clear how the mould got there in the first place then potentially an inspection by an external professional or someone experienced may be able to assist. Now there are many products available to remove mould and yes, you can search these on the internet. We are not the mould experts but we do ask you to be mindful that some products will just discolor the mould but not remove the spores and so the mould can come back. Please ensure that you do do your research and ensure that the product or service you have is right for the situation. Now one of the new minimum housing standard points is that the property needs to be free of vermin, damp and mould at the start of the tenancy. Responsibility after that will depend on what causes the issue. So if you are a property owner or manager and you are aware of any tips or tricks that will help to avoid mould in the property then we encourage you to pass that information on to the tenant. So if you know, for example, that you've got an evaporative air conditioner or evaporative air cooler and running it constantly causes a moisture build up and leaving it off for a few hours here and there will avoid that situation and avoid mould. We really encourage you to have those conversations with your tenant and ensure that they're aware of ways and opportunities for them to avoid mould building up in the property. So when it comes to air conditioners it is another topic that we do get questions here quite regularly at the RTA. So the lessor is ultimately responsible to keep the premises and inclusions in good repair and this does include the air conditioner. Now the tenant can be responsible for cleaning filters and keeping the unit itself clean but these things again should be set out in the special terms and the tenant should be aware of the requirements before entering into the agreement. Any other repairs are generally likely or likely to be the lessor's responsibility. Now one question we do receive regularly is that of regular maintenance or services? Now there's nothing in the act that requires it specifically but as most of us regularly service our cow to keep it running smoothly it might be a good idea for lessors to consider doing something similar with the air conditioner. It's also a good idea for property owners or managers to provide the tenant with a copy rower of the air conditioning manual. This will provide details about how to remove filters for cleaning and other troubleshooting tips that the tenant can check before needing to get a technician. The more information provided in the agreement special terms or by providing manuals or instructions the smoother things can run. Now we spoke earlier about watering lawns and topping up pools. So how does all of that impact water charging? And most of you will be familiar with the water charging requirements as per the legislation. So I won't go into too much detail about that. You'll see the fact sheet there on the screen. We do encourage you if you have any questions around the water charging aspect of things or looking for information around water charging to jump on and have a look at that fact sheet. Now if there is an expectation for the tenant to maintain lawns and gardens to a particular standard and that requires regular watering especially during dry periods then consideration might need to be given as to what portion of the water that the lessor is going to cover. We mentioned earlier ensuring that special terms around garden maintenance and pool care are included. We suggest the same when it comes to allowances for water. So what happens in an agreement where there's an extreme weather event during the agreement and that impacts the special terms. Maybe it's a dry, long, long dry period and the tenant needs to use more water than agree or it might be wet and the tenant doesn't need to use any water that's been provided for them. So that can impact the charging and what might be in the special terms. We really encourage the parties to work together in these situations and find a solution that works for both. Obviously if you're unable to resolve the matter yourselves then you can lodge a form 16 and come to the RTA for dispute resolution. So let's expand a little on the extreme weather event and look at a dry period and where it gets to a point where water restrictions come into play. Now as you'll see on the slide there the tenant is required to abide by any water restrictions that are in place and this will need to be taken into consideration if a tenant's ends. So even though you may as a lessor have expectations that the gardens and lawns will be handed back to you in a particular condition if water restrictions stop the tenant being able to water then obviously the property is not going to be given back to you in the condition that you expected. So in those situations you need to take into account the reasons why and then make your adjustments when you're doing your end of tenancy inspections and those sorts of things. Again communication between the parties in these circumstances is important as there may not be anything written into the agreement to cover something that has occurred midway into the tenancy. So when it comes to the condition of the property at the end of the tenancy we'll touch on the basic requirements and then recap some of the considerations that we've discussed so far today. So as you'll be aware and well aware that the tenant must leave the premises in the same condition it was at the start of the tenancy fair wear and tear accepted. The tenant obviously must also comply with any special terms in the agreement about the end of the tenancy. Now lawns and gardens will be assessed or included in assessing the condition of the property at the end of the tenancy and that's why it's important to consider what we've discussed today. Now we spoke earlier about not leaving things to chance and ensuring that your special terms are well written. If they are then it can make things a lot easier for both the tenant and the property owner or manager at the end of the tenancies as expectations are set out clearly and both parties know where they stand and what they're required to do. So as we've discussed today when assessing the condition of the property at the end of a tenancy then the property owner and manager may need to consider if the changes in weather conditions or the introductions of water restrictions have impacted the premises and take that into consideration when looking at the condition of the property at the end of the tenancy. So when we're putting today's webinar together and you may recall through the registration process we asked you to provide us with any questions or topics that you wanted us to cover. So an example of some of those questions are up on the slide there and I'll just run through a little some responses in regards to those. So a question was raised around tenants in community housing and who's responsible for lawn maintenance. So as I discussed earlier it can be the tenants responsibility to mow lawns and weed gardens and keep things maintained to a basic level. Some of the things that you probably need to consider from a community housing aspect of things is whether your tenant actually has the capacity to do those things if you're putting them into the special terms. So do they have the physical capability? Is there a mower supplied or does the tenant have one? And what options are available to the tenant? So do they need to arrange if they're required to maintain do they need to arrange a lawn mower company to come in and do it and those sorts of things? So by all means there, as I said there's a general expectation that the tenant can be responsible for lawns and garden maintenance but you do need to consider the capacity of the tenant and the circumstances around the tendency in that situation. So it really does need to be assessed on a case-by-case basis. Your expectations should be agreed up front and noted as special terms. So while we're on the topic of lawns we have some questions here around lawn grubs, lawn or plants dying and the cost of water use due to dry conditions and the extent of care that a tenant has for maintaining turf and especially new turf. So hopefully a lot of the information I covered earlier has answered some of the questions around the tenant's responsibility for weeding and mowing but just to recap and as I said a moment ago it's not unreasonable for that tenant to be expected to mow and weed but your agreement should set out their responsibilities. The tenant does need to leave the premises as near to was at the start, fair where and tear accepted. So as we mentioned earlier this can extend to lawns and gardens but as we also discussed where the conditions need to be considered when assessing these things. So if you get heavy rain periods you've provided allowances for getting rid of lawn clippings and those sorts of things. What does the tenant do? If there's more clippings that can go in the bin all of those sorts of things need to be considered. Are we really encouraging in extreme weather conditions that you do have those conversations with your tenants in those circumstances? So if plants or lawns are dying then you need to have a look at why. So what do the special term state about looking after them? Is it allowance made for water? Is the tenant under watering or are they over watering and causing issues? So you may need to look at what's going on there and if the tenant isn't meeting their requirements under the special terms then they can be considered to be in breach of the agreement. Now the question about lawn grubs is a great one. If you know that your property is susceptible to lawn grubs then I'd suggest you advise your tenant of what to look out for and ask that they advise you as soon as possible if they notice any signs of lawn grubs. It might be a good idea to arrange for spraying. Lawn grubs are an environmental issue so it's not the fault necessarily of either party but we do suggest that both parties work together to find a solution. And at that early observation and picking up early that there is an issue can avoid any problems. I've had issues with lawn grubs at home and I know it can make an absolute mess of your lawn. I didn't get onto it early enough. I now know what to look for. So if you do and are aware of the sorts of things let your tenant know what to keep an eye out for. She had some questions around air conditioner services and gutter cleaning. I'll touch on the air conditioner service and I did speak to this when we spoke about air conditioners around that aspect of regular maintenance. So as we said there's nothing in the act that requires regular maintenance or services on a regular basis. But really as we talked about and use the analogy in regards to your car if you're regularly servicing then you've got a better opportunity to ensure that the life cycle or the life span of your air conditioner is better and that it continues to work as it should. Now if the owner does refuse to agree to regular services then there might not be a lot that can be done but if a failure to service it causes damage or causes the output of the air conditioner to diminish to diminish then the owner may find themselves requiring a technician anyway because the act does require the inclusions to be in good repair. So it's also important to mention here that if the special terms require the tenant to keep filters and the unit clean then they do need to do so. So a lack of cleaning from the tenant's perspective that leads to damage could find the tenant footing bill for repairs. So I mentioned appliance manuals earlier if one hasn't been provided that remember that throwing the maker model into a search engine such as Google be able to find most manuals and give you some information around what to do and how to look after those particular things. So when it comes to gutter cleaning this is a question that we've been getting in our contact center for years. Now the act is silent on the topic of gutters specifically but it does make reference to obviously ensuring that the premises are clean and fit to live in and that it is maintained in a way that remains fit for the tenant to live in. Now it might be reasonable to expect that regular gutter cleaning is a less or responsibility as a regular maintenance issue as it's highly unlikely that the tenant is actually doing anything to cause the gutters to fill up. If the less or doesn't or complete regular maintenance on the gutters then the risks could be water backing up and leaking into the walls or causing damage to the premises. So the less or may look to add something to the special terms here but again they need to consider the tenant's ability to be able to do so safely. So if you've got a high rise Queenslander it might not be reasonable for the tenant to be able to access the gutters to keep them clean in that situation. So it is important to consider the safety aspect both of the tenant but also of the gutters building up with debris and leaves and that sort of thing. We've already had multiple bushfires this season and summer has just begun and now we've got in Northern Queensland the potential of a cyclone. So gutters that don't allow the water to disperse could be a risk and cause damage in that situation. So it's also worth checking out QFES's website it's Queensland Fire and Emergency Services website for details around preparing your property for emergencies and Deb will drop a link into the chat. Now that's it for me in regards to the information that I've got. If anyone has any questions certainly let me know. Deb have we got anything there? Yep. So Donna just wanted to clarify about the pool safety certificates. So her question was does the pool safety certificate get included in the tenancy agreement? Or is that something that you maybe provide with it or is it just on display near the pool? What are the expectations there? So the best thing to do, Donna would be to jump onto the website that we've provided in regards to pool safety. My understanding is for a shared pool so in a unit complex my understanding is that it does need to be provided copy provided near the pool for an individual property with a pool then we do recommend that a copy of the certificate be provided with the tenancy agreement. So just as an addendum or part of the special terms but a copy of the certificate be provided in that way. Yeah, thank you Mark. And then the other question that came in from Elisa was around whether special terms have to be written by a solicitor. So that is a good question. We actually did an information recording a couple of, well about a month ago I think or a little bit longer on special terms and we did address this in there. So for, if you're a property manager you can't write special terms into the agreement yourself. They do need to be written by a legal expert or legal practitioner. If you are a property owner writing a tenancy agreement you are able to write your own special terms in but the key to that is that those special terms do need to meet the requirements of the act. I would encourage you to jump on and have a look at that information piece that I did a couple of months ago because it does provide a little bit more information around your responsibilities of special terms. What is able to be included? What falls outside of the act? Who's responsible for writing and those sorts of things as well? Thanks Mark. That's all the questions that we've gotten so far. If anyone has any other questions you can pop them in the chat real quick. Hopefully the information's been thorough enough Deb that we've covered everything that we need to. But if anyone does have any last minute things certainly let us know. And thank you for the questions we received when you registered too. They really help us to make sure we're covering what you want to know. And just before we do finish up and we'll keep an eye on if there's any questions come in. So just from an RTA perspective please make sure that you've signed up for our monthly RTA news email so we can keep you informed of any key topics or changes. We do produce a range of educational resources including recorded webinars on tenancy legislation and key topics. We also have a Talking Tenancies podcast series that goes through a whole range of different topics and are really interesting to listen to as well. So there's a lot of detailed information on the recent tenancy changes if you are looking for information there. And you can access both the podcasts and our webinars through our website. Now this is our last webinar for this year. As I said before there will be a short survey that pops up at the end of the session and your feedback within those surveys helps us to continue and improve our communication and gives us ideas for topics for webinars and podcasts for next year. So please if you do have the time take the time to fill that survey out and let us know. We also have a LinkedIn. So if you are on LinkedIn feel free to jump on there and follow us as well. And one lucky last question Mark from Nari who wanted to know if hedging is standard lawn care or if it should be an addition in the special terms. Yeah again if it's fairly standard if it's a not too high and not too difficult to manage the hedge then it can be put in as a tenant responsibility. But if you've got a six foot high hedge or intricate that needs to be shaped and all of those sorts of things then that may not necessarily be the responsibility of the tenant. But if it's a three foot high and it's neat and it's square and it's fairly simple and you can provide the instruction to the tenant and be confident they have the ability to do it then yeah there shouldn't be any reason that you couldn't add that to a special term and have that as a tenant responsibility. Okay, thank you Anne. Sorry we've got one more question. So can 100% water consumption be charged and still have a requirement to water and plant lawns or should there always be an allowance of water for the garden? I think it's the question is asked. It's a fair question in regards to water charging the tenant can be responsible for 100% of the consumption. I would argue or suggest that if there are expectations and especially if you are looking to have gardens maintained to a particular level and lawns maintained to a particular level then it might be reasonable to consider providing an allowance within that. There's nothing specific in the legislation. The legislation simply says that the tenant can be responsible for 100% of the water if the property's water efficient and the agreement provides for the tenant to pay water but some of the I guess disputes that we do see at the end of tenancies are around that water charging aspect where the lessor has an expectation for the gardens and lawns to be maintained and are not providing any water to do so. Now in the last few weeks in Brisbane it wouldn't be an issue because you probably wouldn't have had to turn your tap on but certainly in the six months prior to that where it was really dry then the tenant potentially needing to use more water than what they may well have done to keep those lawns up standard and that sort of thing. So it's probably not unreasonable to expect or to provide an allowance but there would be nothing preventing you from charging the tenant 100% in that case if you wanted to. Okay, thank you. I think that's it for our questions. All right, thank you very much for those. Hopefully I've answered those and provided a little bit more information. Just finally before we do finish up to our contact details which you'd all be very much aware of but obviously the contact centre is available from 8.30 to 5.00 Monday to Friday on 1300-363-111 for those requiring interpreter if you call that number and you will have free access to interpreters if you so require and obviously all of our information or a lot of information can be found on our website anytime it's 24 seven. So we'll do appreciate you joining us today and stepping through that information with us and we will hope to see you in 2024 for when we start our webinar series again next year. So thanks very much and I will now end the webinar.


Hello, I am Dr. Sunil Kini, consultant joint replacement and arthroscopy surgeon at Manipar Hospital's Bangalore. It is important to note that post knee replacement, it is normal to have pain for about 3 months after surgery, albeit that the pain actually decreases over the period of time. But there are some ways in which the pain can be taken care of. Firstly is the judicious use of analgesics or anti-inflammatories as prescribed under the eyes of your surgeon. It is also important to note that certain activities like your physiotherapy on a daily basis can reduce the swelling and subsequently the pain as well. Also the use of icing is regularly being practiced to reduce the swelling and the pain both in this scenario.


It's thinned out a bit today. All right, it's Friday. Everybody's excited about Friday? I'm excited about Friday. OK, so today we're going to talk about threads and how threads are implemented. And at the end, we'll talk a little bit about thread states. I just was noticing, I think that is my favorite feature of this room by far. The periodic chart of the elements that's up on the wall, can anybody read it? I mean, I can't read it from here.  But I mean, it's a nice idea. It just needs to be like eight times that big. All right, so as you guys probably know, the design doc and code reading questions for assignment two are due today at five. And the goal here, again, is that once you've done the design, and once you've done the code reading questions, you must be just itching to get on to building assignment two, implementing these system calls and getting your system to actually run real user programs, which is actually super exciting. On the other hand, I mean, the thing I always have to remind people is that, and the website tries to do this, but with a limited degree of success potentially, assignment two is a lot harder than assignment one. Like a lot harder. Once you get through assignment two, you have some idea, you can imagine at least what assignment three is like. Assignment three is harder than assignment two, but they're more similar to each other. So please, you guys have three weeks, I think. Is that true? Three weeks from today to complete the implementation? That's plenty of time to do this. However, it's not plenty of time if you spend 20 of those 21 days thinking, eh, my partner and I, we knocked out assignment one in an afternoon. We're cool. Then you guys will hit a big train wreck. So I'm giving you guys a lot of time, but I'm not giving you the time to just sort of hang out. Like please start working on assignment two. Look, if you start working on it and you get it done in a day, great, then you can chill out and start studying for the final or midterm. But please use some of this momentum to get started. At least sit down and try to write some of the file system system calls and get a sense for what you're in for. Because again, assignment is not easy. And it's a lot harder than assignment one. Any questions about logistics before we go on? All right. You look like you wanted to ask a question, but you didn't. Do you have a question? Or is your hand just in the question position? OK. All right. So let's talk a little bit about thread transition. So when I stop one thread and start another thread, what does that call? It's called a context switch. What were some of the CPU limitations that we were trying to address? We've built up all this machinery now. We can stop a thread at any point and restart another thread. Why are we doing this? What are the limitations of the CPU? And this is something we'll come back to. In every case, when we do a unit in this class, there's some limitations with hardware that the operating system is trying to address. We'll do that when we talk about memory. We'll do that when we talk about the disk. With the CPU, what are the problems with the CPU? What are the limitations with the CPU that the OS is trying to make go away? Why am I doing this in the first place? So there's only one processor or N processors. So I don't have very many because they're expensive. And it's also a lot faster than the rest of the system. So the first maybe is a limitation. I wouldn't call it speed a limitation, but the fact that the processor is so much faster than the rest of the system is what gives me the opportunity to play these games with how threads are scheduled. So I'm trying to keep the system as busy as possible. So what is batch scheduling? Let's say I have a series of things I need to do. How would a batch scheduling system process those tasks? What is batch scheduling? I can use my thing. Oh, no pictures, apparently. Alex here? No, Alex? How about Jason? I need a photo. I can't see the people. All right, batch scheduling. Mojit. Now I have pictures. I need to start using this to take attendance clearly. How about four? Ananda. Batch scheduling. You guys have a few minutes to think about it. Look for the notes. Yeah. Right, so I run a job or a task until it's done. And then I run something else. While it's running, it has full access to all the system resources. Nothing else is running at the same time. So I'm running things one at a time. This is not anything I'd ever want to do in an interactive system. It's not a bad idea, though. And this is done in some data centers for various reasons, particularly when I have jobs where no one's eyeballs are waiting for the result. But what's the problem with batch scheduling? Why don't I do that? Yeah. Right, remember, the CPU is a lot faster than the rest of the system. So while the job is running, it's likely that the CPU or other parts of the system. Memory 2 is faster than the disk. So it's unlikely, unless I'm very, very careful about the job that I've created, that batch scheduling is going to lead to good use of system resources. OK, so now, again, how do I, you guys, when you interact with your computer, you think that multiple things are happening at once. What's actually happening? Pretend that you have one processor. Maybe some of your smartphones still only have a single processor. What's happening? Yeah. The periodic table will answer my question. Exactly. So I am switching back and forth between tasks really quickly. I'm writing a little bit of one thing, and then I'm writing a little bit of another thing. And what you experience that as is, for example, the mouse is moving, and at the same time, Firefox is rendering the page behind it. You guys are probably most conscious of this when you're using your GUI, when you're acting with the graphical user interface, because there's a lot of stuff going on. There's things are spinning, and the YouTube video is playing, and some banner ad is scrolling by, and your mouse is moving, and so all that stuff's not happening at the same time. One of those things is doing a little bit of work, stop it. Somebody else runs, and I continue this process. OK. So how does the operating system make sure that it retains control over the processor? I want to make decisions about how to allocate the CPU on the operating system. I'm in charge of multiplexing system resources. This is my job. How do I ensure that I get a chance to do it at a regular basis? Yeah. Yeah, I use a periodic timer to generate hardware interrupts. Those interrupts cause the operating system to run and get control over the device. Every one of those interrupts is a potential point in which I can make a scheduling decision and decide that I'm going to stop the process that was running right before the scheduling, the timer interrupt took place. And we know this stuff. The timer interrupts, however, mean that I'm going to schedule the threads preemptively. Cooperative scheduling is this idea that threads are only descheduled at moments when they would expect to be descheduled. I made a system call. I know that I'm going to trap in the operating system, and it's possible I'm not going to keep running. In the kernel, you guys have a mechanism for cooperative scheduling. What is it called? Maybe something that you guys saw in the Assignment 1 testing code. In your OS 161 kernel, there was a function that I would have to use if I was going to try to cooperatively schedule threads. What is that function called? Thread yield. Thread yield says, hey, by the way, you can deschedule me right now. I'm cool with that. I'm right here. I'm just telling the operating system it's possible that you could deschedule me. We don't rely. Now, this is something that's potentially useful in the kernel. Remember, the kernel is in charge. The kernel is the boss. The kernel is written very carefully. But the kernel does not trust user programs to do this. One way of doing scheduling would be to require unprivileged code, unprivileged user applications to call thread yield. And that would be the only time that the OS had a chance to reschedule the CPU. That's not how it works. And when we start the thread up again, we want it to appear that nothing has happened. And we pointed out that there's limitations of that. Obviously, time has gone by. The device is in a different state than it was. But there are certain invariants that we want to preserve. We want, for example, all the registers to be the same as they were when I stopped the thread. What is the thread state that I need to save in order to perform a context switch? Well, I just told you one thing. I need to save the registers so I can reload them when the thread restarts. What's the other piece of state? Yeah? Stack. Stack. So these are my two pieces of private thread state. And keep in mind, we talked about this right at the end of class. Somebody brought this up. It was a great point. There's an overhead to performing a context switch. I have to enter the kernel. I have to save all this state. And what this means is that there's a cost to transition into the kernel. And we're going to come back to that today when we talk about different ways that you can implement multi-threading. Because we'll do a little bit of a design exercise at the end of class today, where we talk about two different approaches to implementing multi-threading. One in user libraries, one in the kernel. And we'll talk about some pros and cons of each one. And just a hint for a later question. One of the cons with doing multi-threading in the kernel is that there's a cost to switch between threads. And the cost of the kernel is actually potentially higher than the cost to switch between threads if those threads are implemented in a user space library. This is one of the trade-offs. And we also pointed out that I can't run the timer that drives scheduling too fast. Because if I do that, then the overhead of doing all these context switches, which, again, is totally useless. Useless except to achieve the illusion of concurrency. If I'm doing this too often, I have a lot of wasted cycles. And the machine is going to start to slow down. Luckily, you guys are so slow to perceive things that the kernel has. I can run the timer at reasonable rates and still get very, very good interactive performance. I wish Guru was here. Maybe somebody else knows this, what the default scheduling quantum is on Linux these days. Guru knows the answer to this question. It's one of the things about him that's so awesome. But I don't remember what it is. But I think it's on the order of milliseconds. It's actually pretty long. OK. Questions about this stuff before we talk about threads? OK, great. I did such an awesome job of explaining it. OK, so at this point, you guys sort of know what this is. So what's a thread? We talked about switching between threads. We've talked about saving the state of a thread. What is a thread? Yeah. Yeah, so it's the way that we abstract the CPU. That's a better answer to the question than I have upon the slides. What does a thread consist of? What's that? I heard a wrong answer over here. From the periodic table, clearly. Stop it.  You don't even know anything about computer science. OK. Two things that a thread consists of. You just did this, registers, and a stack. That's really what a thread consists of. This is the state that's private to a thread. Anything else is part of the process, right? The address space, the file handles, things like this. This is what we consider to be thread private state. The registers, which represent the CPU. And the stack, which maintains some history of what the thread was doing. The stack is also an important way that threads save state. Yeah. Yeah, we'll come back to that. That's a great segue. I actually have a slide about this in two slides. So can we do that? And then you can tell me if it's still. Yeah, so a lot of times, particularly for your OS 116, when we kind of talk about threads and processes interchangeably, which is a totally OK thing to do as long as there's a one-to-one mapping between them, right? You guys are not expected to do anything else than implement a one-to-one mapping between threads and processes. So people for assignment two will come to me and be like, well, do I need to have a separate process structure? And I always say, well, I mean, you're going to have your thread structure. It's going to have a pointer to your process structure. Your process structure is going to have a pointer back to your thread structure. So you are totally welcome to create a completely new, unnecessary structure and two more pointers that you have to maintain and ensure don't get corrupted, but that's up to you. If I was doing it, I would probably put that stuff inside the thread structure and call it a day. Fewer pointers means more beers in general. So yeah, when you're talking one-to-one mapping, but we'll get back to this later today, and there are certainly times, and it's very common, obviously, to have multiple threads inside a single process. How the OS views that is a good question. So actually, let's talk about that right now. So are registers private to a thread or part of a process? Top part of the slide. So registers are considered private to a thread. Stack, also private to a thread. What about memory? Shared between multiple threads. So this is now part of the process. If a thread writes to memory, another thread can see that that right. Now, this is a little weird, though, right? So I just got done telling you that the stack is private to each thread. Where is the stack located? In memory. So it turns out that if you are careful about how you do it, you can actually access variables on other thread stacks. The caveat is if you are careful about how you do it, because it's very, very hard to do right. But inside a traditional UNIX process, all the threads that are part of that can access all the memory that's been allocated to that process. So if I want to, I can poke around on your stack. Again, usually not a very intelligent thing to do, right. Better to allocate an object on the heap, and then we can share that object together, right. But there is usually not necessarily any protection provided in user space to thread stacks. They're just typically considered to be private state for that. Does that make sense? So technically, they're stored in memory, which is part of the process. In reality, they're usually not shared, right. That's not where things that are shared by multiple threads live. File to script or table. Process or thread? Process. I should have put these in a different order, because it's kind of obvious. So now we have a diagram, really fun diagram. Here's my thread, right. That thread has registers in a stack. The address space, now I wish I had another thread here, but if I had another thread here, I'd have another one of these guys with multiple registers and its own stack, right. So the stacks when I have multiple threads are usually put up sort of high in the address space and usually separated from each other far enough so that if I make a bunch of recursive function calls or something, my stack doesn't overwrite the guy next to me. OK, and the file table's proposed. Any questions about this before we go on? Gila, did I get your question answered? Cool. Are registers physical things? That's a great question. What's that? No, no, no. So you would not share registers, right? Are registers physical things? I mean, registers are provided by the CPU as a way to hold a value, right? That's the fastest form of storage that the machine has available, right? Can they be shared between threads? No, not that I know of, right? It's hard to say no about stuff like this because people will build all sorts of weird stuff, right? So who knows? There's probably like some machine that was like, this would be an awesome idea. I'll let thread share registers, right? Like when a thread's context switches up, I'll just leave stuff in there for the next thread to find, right? I don't know why that would be useful, right? But that doesn't stop people from making it, right? Just because it's fun. And sometimes you build things just to see what happens, OK? Good question. Any other questions? All right. OK, so here's the thing, right? I mean, you guys are, to some degree, I think a lot of you are comfortable with threads, but why do we use threads? Why don't we think about threads? Because what I'm going to try to do in the next few slides is convince you that threads are sort of the ultimate abstraction because they're not, they provide you with a nice way of thinking about how the system works. But they're not actually required to achieve concurrency. We'll come back to that in a minute. But why do you guys, why do we use threads? Why does the idea of a thread make sense to us? What's sort of intuitive about it? Let's say I have a web browser, and my browser's got a bunch of threads. How do I usually divide work between those threads? Give me one example of something that a thread in a web browser might be doing. Yeah. Oh, I like that answer. Blocking ads. Yes, sweet. Yeah, definitely, right? Definitely on my web browser. So yeah, but the answer to that question is really, I think, really indicative of how we think about threads, right? Threads represent one of multiple things that a particular process is doing quote unquote simultaneously, because while I'm blocking those ads, I'm also rendering the page and responding to clicks in various menus and stuff like that. So again, I mean, there's multiple things that are going on. And we know at the low level, what's happening is things are constantly getting started and stopped in order to make it look like all this stuff's happening at once. But in reality, the way we like to think about it is I have one thread that's rendering my page and one thread, like Firefox, for example, might have, I should stop talking about Firefox. I don't use it anymore, and I'm proud of that. Chrome might have one thread per tab. Makes sense. You have a tab. That tab has something that needs to get done. I have a thread that's allocated to that. So this is really a mental model for us to think about how we structure concurrent programs. Threads also frequently and naturally encapsulate some data. So there's data that's private to the thread that's blocking the ads. So there's things that it cares about that other threads don't really care about. Like it might have a list of all the ad servers on Earth, and it's using that to filter out content and make sure that I don't see ads for herbal biographies. And the other thing, and this is really important, right? So threads can block. As programmers, we really like this illusion that I can be doing a bunch of stuff and then I can make some sort of blocking call, like I might read a file. And my thread will block until that finishes. And that's OK. I'm allowed to do that. And essentially what's going to happen is, to me, it looks like this one call just happened, and now I'm underneath it, and I keep going. To the machine, what happened is that you did that, and then I got a bunch of other work done. And I restarted you sequentially. We're going to come back to this in a minute, because there's other ways of doing things. So here's my favorite example of threads. This is a picture from my wife and my favorite restaurant in Cambridge, Massachusetts. And this is a nice example of Wikipedia getting something right. So threads, you can think of threads as multiple cooks in the same kitchen that are trying to prepare a meal together. So normally, if you look at well-run, really efficient kitchens, there's a separation of tasks. It's not just like anyone's doing anything. You've got the one guy who's in charge of chopping vegetables or whatever, and the other guy who's watching the soup or the other guy who's cooking stuff on the stove. So each one of them, they've broken the task down. They're each doing their own thing. They're probably doing different things. No, they may not be. If you went to some huge restaurant, if you were on a cruise ship, I bet they have a lot of people chopping vegetables and cooking french fries. Apparently, french fries are one of the number one things to get eaten on cruise ships. And now, if they're working together on a recipe or to handle a whole bunch of diners, they're all trying to follow the same plan, but they're working on different parts of it. So that recipe is sort of like the source code of the program. They all have access to all of them, but each one of them is probably confined to one particular area. They have private state. So what's the equivalent in this cook's example of private thread state? Yeah. Yeah, like whatever's going on in my little mind. All the stuff that's up here. I know stuff. And I gather data about my own environment that's important for me to process. And other people really don't care. Like no one really cares exactly what percentage of the vegetables that I'm chopping I'm done with. But that's for me to know. On the other hand, they have to coordinate. So they also have to communicate with each other. They have to talk. They have to say things. There's nonverbal communication, whatever. So this is, again, sort of a nice analogy to think about the difference between processes and threads and also some of the, and maybe this sort of thing is why threads are such a natural abstraction for us human programmers to think about. And if they don't, then you can have stuff like this. There are so many cake fail pictures on the internet. You kind of wonder if people are doing this on purpose. OK, so anyway, I want to talk a little bit about event-based programming. And I think this is a good time to do it. How many people have ever heard that term or done any event-based programming? Cool. I know it's taking over. It's really exciting. So threads are a reasonable way of thinking about how things work and how to program concurrent systems. But I don't want you guys to get the sense that they are the only way of doing. And sometimes they're not even the best way. So going back 10, 15 years, my PhD advisor wrote a dissertation about how to write high-performance web servers. And one of the ways to do that was not use threads. So these big, multi-threaded web servers, it turns out that when they get under really, really heavy load, like it's 10 AM on the morning of 9-11, they just shut down completely. They can't make any forward progress. So if you look at the load curve, it's like it goes up like this. And then once they get to a certain load, they're just not satisfying any requests anymore. You want your web server to keep plotting along. You want it to keep making progress, even if it's really busy. You don't want it to just go to the point where it can't serve a single request. But this was what was happening to a lot of web servers in certain cases. Like after an earthquake, everybody suddenly finds the web server of this poor guy at the National Geological Survey, whose web server has been getting like one hit a day. Suddenly it's getting like 1,000 hits per second. And it just goes, phew. OK, so another way to do this is something called event-driven programming. And some of you guys have done some of this. Some of you have been forced to do some of this. How many people have ever written a JavaScript and a web browser? Well, you've done event-based programming, because a lot of that's heavily event-driven. What do you do in JavaScript? You write little event handlers that happen when certain things on the page take place. On click, do this thing. That's an event hand. That is not. And so that's a little bit of a taste of what event-driven programming is like. And has anyone worked with Node before? That's cool kids. You guys should check this out. This stuff's awesome. It's essentially like all these people. So again, how many people have written client-side JavaScript? There was a larger number of hands up.  So you decided, hey, let's run JavaScript on the server as well.  And now they're taking over the rest of the internet. It's a little frightening. So here's an oversimplification of how this works. Threads can block. So what we think of doing with the thread is doing, potentially, some long-running task that can have delays at any point in time. And the way we think about those delays is you did something that took a while, and you stopped running, and something else ran, and then you started running at the next state. In a lot of cases, the right way to do event-based programming is to write event handlers that are so short that they don't ever block. They do a little bit of work, and if they need to block, they produce another event that somebody else has to hand. So this is a totally different way of thinking about how to achieve concurrency on systems. So if I have multiple threads, getting good concurrency sort of relies on switching between them. When I do event-based programming, getting good concurrency relies on writing those events in a way that I can process a lot of them really quickly in a row and keep the system busy. Anyway, I just didn't want you guys to get the sense that threading was the only way to do this. So let's think about some. We did this at the beginning of class. It was probably good to come back to it. Give me some examples of applications that are naturally multi-threaded. Yeah. It controls what? You guys feel like this is like a great example day. We had to add block. Now we have drones. Yeah, like a drone, because it's up there. It's got to fly around. It has to spy on people and has to fire missiles at them and kill them. It's got a lot of things to do. Or if you're running one of those drones, maybe it's just hovering over someone's wedding being annoying. Who knows? But it has, at minimum, even just to control the thing. It's got like four different, again, I wish Guru was here. Guru has this little drone he's been building in her lap. I have no idea what he's going to do with it. But when he attacks the White House, I had nothing to do with it. I should actually really be careful. Anyway, so you've got four little motors on that thing. They're all pushing in different directions. So yeah, a drone is a good one. What else? We started with drones. We're going to get somewhere good with this conversation. We just go on long. That's another naturally piece of natural multi-threaded stuff. Web servers. So that's a great example. A lot of times, web servers use a separate thread to handle in each incoming connection. The connection comes in. I fork off a thread to handle it. That thread will block potentially multiple times. And eventually, that thread is responsible for taking that request, doing any of the processing on the server side. Maybe I have some Python to run. Maybe I have some Node to run, whatever. Well, Node wouldn't do it this way. They would do it differently. But anyway, doing all the stuff I need to do. And eventually, at the end of the day, that thread hands off a web page to a waiting client. So this is how a lot of web servers work. Well, usually, I don't fork a new thread.  But as requests come in, I hand them off to a thread. And that thread goes into the desktop. Web browsers. So again, I have multiple threads for every open tab. Frequently, I have, hopefully, you guys have noticed this. I mean, probably I haven't noticed it because you probably were born after it started to happen. Web pages used to just load all in one big clunk. It was like you went to some website and you sat there and it spun for a minute. And then suddenly it was like, whomp. That's not what happens anymore. You go to the page and the text comes in really quickly.  And this is because there's been a huge amount of work on figuring out how to process web pages more efficiently.  I want to start reading the article.  In fact, I probably don't want it to load at all. So scientific applications. There are some types of data sets that can be easily split up so that multiple threads can work on them together. Sometimes this is also done with multiple processes, but you can certainly do it with multiple threads if you're lucky enough to have something where you can communicate with memory because then you're doing it better. So go back to the data sets example. So when I have something that I want to break up and process, why not use processes? So you guys are probably going to have to do this at some point in your lives. You're going to have something that's going to, you're going to figure, I need some degree of concurrency to solve this problem. And you're going to have to make this design choice. Do I do it with threads? Do I do it with multiple processes? What's the downfall of using processes? So remember, IPC, getting processes to communicate is a lot more difficult than getting threads to communicate. There's a lot more overhead potentially. There's more tricks you have to do to set things up properly. Inside a process, you want two parts of it to communicate. Just spawn up a thread and off you go. It's super easy. Getting IPC to work properly is usually more complicated. I think at some point earlier in the semester, someone came down and we were looking at some of the output from one of the PS dumps when we were looking at Apache. A lot of applications today, though, do a mixture of these things. So I think modern versions of Apache have this do this weird thing where they both fork and clone. So they create some threads, but they also create some processes. And they do this for performance reasons that I don't want to get into in depth. But in certain cases, having multiple processes can be difficult. IPC overhead design. And there's some state associated with processes that doesn't scale particularly well, like the address space, for example. OK, so now let's talk about two different ways to actually implement multithreading. And this we're going to get away from the one thread per process model. You can implement threads in user space using unprivileged libraries. In fact, on Linux for a long period of time, this was the only way to get multiple threads in your process. There's a library called pthreads. And there are other libraries that do similar things. Or you can actually implement threads in user space. I think this is one of those things that really starts to hit home, that threads are an abstraction. Because if you could implement the abstraction in user space, then it's not really part of the kernel's multiplexing responsibilities. I can't multiplex things all the time in user space, but I can't implement some of these abstractions. And threads are one of them. So we refer to this as the M to 1 threading model. Because as a result, what happens is the threads are implemented in user space. The operating system doesn't know about them. The operating system thinks, from its perspective, it's like there's one thread in that process. And that's all I know about it. It turns out, behind the scenes, that process is using multi-threading internally to get more performance. But the OS has no ID. And part of the pros and cons of these approaches have to do with the fact that the operating system doesn't know what's happening. And there are certain things you can't take advantage of. You can also implement user threads in the kernel directory. So the kernel could provide a way for user processes to create multiple threads. This is pretty much completely ubiquitous by now. User space-studying libraries are still in use, but I think most modern operating systems provide this feature. This we refer to as the one-to-one threading model. So every user thread is visible to the kernel. The kernel knows exactly how many threads are actually present in a particular program. So again, this is the M-to-1 model. From the kernel's perspective, all the kernel sees is one thread, despite the fact that the user program has used a library to create multiple threads. We'll talk a little bit about how this is done in just a minute. This is the M-to-M model. I do sort of a gratuitous diagram, but just forgive me. So implementing threads in the user space, how do I do this? It seems like something that the operating system would have to do. But the first thing is I've hinted at is that this doesn't really involve any multiplexing, so it is something that I can do. And let's think about how I do a couple of the things that I need to do to implement threads. So how do I save and restore context? How do I save context? Yeah? It's just the registers for the thread, right? When you're a thread, you can copy the registers out of the CPU, no one's stopping you. They're your registers, you're running, right? You just say, OK, I'm going to grab the value for A0 and put it in this structure, right? There's nothing privileged about that code. That code's not using any special instructions. It's just copies, right? Pretty simple. So I can take that block of code that we saw in your kernel. I can move that to user space, and it works exactly the same. It just takes all the registers that I care about saving, stuffs them in a structure somewhere. OK? The C library actually, so we'll get to this in a minute. This is, I mean, of all the things you can do with C that are bewildering and weird, this is probably up there at the top of the list, right? And to be honest with you, most of the things that you can do with C that are bewildering and weird are like causing errors, right? This is not causing an error. This is actually a function. Has anyone ever used this before? I hope not. I don't even know why these are provided. These are terrible, right? I'm about to show you some of the most un... You could use this. This is probably something that people use for those like, obfuscated code competitions, you know? Have you guys ever tried to read some of those? It's like a single line of pearl that decodes in FB3, you know? It's terrible. So that's the only reason to use this. I'm gonna show it to you because I think it's awesome, but you guys should please don't use this in your code because as you will see, you could use this to write some of the least readable code on Earth, okay? How do I, but here's another question. I mean, implementing multithreading means that I have to be able to stop, potentially if I wanna do preemptive multithreading, I need to be able to stop one of the threads that's running and run another thread. And this is probably important for a bunch of performance reasons as well, right? So this isn't just, you know, it's probably true that a user space library that couldn't do this would have pretty bad performance in a variety of settings, or it would require programmers to be really good about making sure they gave up control of the CPU. So I have to like put thread yields all over the place anywhere where I think that it might be time for another thread to run, which is really, really a bad thing to do, right? But how do I do this? Anyone know? Yeah, yeah, see now that the slides are online, everybody knows all the answers. Yeah, so I use periodic signals, right? So the idea here is that the user space threading library installs a signal handler that's kind of almost like the OS scheduler. That signal handler is attached to a timer that the OS delivers to the process periodically. When that timer is delivered, that signal handler runs and essentially performs the equivalent of thread scheduling, which we'll talk about next week. So this is pretty wild. Now keep in mind, if you're running in user space, this is all cooperative, right? If I have like a bad thread, I don't like the other threads, I could just overwrite the signal handler with my own signal handler and then there goes your threading library, right? So you have to, but again, we're kind of assuming that the threads within a process are willing to play along with each other if they're trying to use this like this. But you could certainly, there's nothing, unlike the kernel, which is always gonna get control back, right?  All right, so now we gotta look at, we gotta look at set up long, okay? So here's my little piece of code, right? I'm gonna go through a loop and here's what's gonna happen. When the value is five, I'm going to save my state and then break out of the loop, right? When I get down here, I'm going to, and I have this variable restored, which I set to zero. If I'm not restored, so I haven't done this already, I'm gonna call long jump, using the state that I saved into this thing that's called a jump buffer. Well, I'll ask you guys, what's in that jump buffer in a minute? And then what long jump does is it's gonna essentially return to the point that set jump, that set jump left. And the return value from set jump is going to be whatever I pass into long jump. So long jump gives it a one. So when I get here, set jump saved is gonna return one. When I go back, does this make sense? This code is, again, this function is a little bit difficult to understand how it works, but who can predict what the output of this is going to be? So clearly for the first few values, I'm just hanging out, I'm printing stuff, I'm gonna print value of I is zero through five. Now I get into the fifth iteration of the loop and what's gonna happen? Anyone wanna guess? Yeah. So here's how the flow of this code is gonna work. I'm gonna go through this loop five times. And the fifth iteration, I'm gonna break out of the loop, but not forever. Now again, you guys thought there was no way to do this and see, and please don't use these new powers for evil. What's gonna happen? I'm gonna get down here. Long jump's that gonna take me right back into the loop. I'm going back in time. And then I'm gonna continue executing the loop, printing off the rest of the values until I exit. So this is the actual output of this code. I'm not sure you could quite compile this. I think I left off a few variable identifiers, but whatever, it's close up. So again, I go through till I get to five. Here I saved my state. Now I saved CPU state and I break out of the loop. So now I should have a printf down here to say I'm out of the loop, haha. But then when I call long jump, I'm back inside the loop again. And I'm gonna continue executing the loop. So now that you've seen this, what are such up and long jump actually doing? What's in the jump buffer? I guess? Yeah, I mean, you could rename the jump buffer the trap frame, right? It's the state of the thread at that point in time. That's what allows me to work back into the middle of the loop, right? And you can do this with, like this is a pretty simple example, but you can do this with arbitrary code, right? I could save the state in the middle loop and then go off and do a bunch of other stuff and then suddenly transport myself right back into that point. Again, terrible way to write code, right? If you find yourself solving a problem this way, then I would suggest that you find another way to solve the problem. All right, any questions about this? I mean, this is a clear indication that we can do this in user space. I can save state in users. This is how I implement this mysterious function, yeah. Saved is this jump buffer, right? That's a great question. That would be on the stack, right? But I could put it anywhere. I could put it in the heap, right? And then the fun thing is I could return from the function, I could do all sorts of other stuff and I'd still have the state, right? That would allow me to get right back to where I was. So yeah, in this particular case, it's on the stack. That's okay because I still have my stack right here. But I'm assuming if you put this on the heap and put it in a more permanent place, then I could store it across multiple function costs, right? I could trade it between threats, right? I could be like, hey buddy, you wanna have my life experience? You wanna like eliminate some ads today? Here's a jump buffer, now you're running my code. How weird is that? Wow, anyway, it's pretty cool. Again, do not, you can use these two tricks to impress your new friends. You may lose a few on the way, but, and this is the meme I came up with. I don't remember what her problem was. It was the vaulting thing, right? That's where she fell down? Anyway, I don't know. It probably should have been nailed to set jump, forgot the long jump, but that's not it. Okay, any questions about set jump long jump? So let's come back to our comparison here and this is how we'll close out today, right? So what's potentially good about doing threading in user space? Why would I wanna do it this way? Yeah, yeah, it's less overhead, right? I don't have to cross the kernel thread, kernel user boundary. There is, now look, there's still some overhead to running the saving state in user space, but it turns out to be smaller than getting in and out of the kernel, right? So the overhead to switch between threads is lower and the thread state's actually quite a bit smaller because the kernel has a bunch of other state about the thread that is necessary for the kernel to work, that a user space threading library doesn't necessarily care, right? What's a, so, again, there are no, I would hope that there are few to no systems left on Earth that require you to use user space threading libraries. Why is that? What can I never do with a user space threading library? Remember, the kernel thinks there's one thread. What does that mean? Why would that make you very sad today? Like very, very sad, yeah. I can never use multicore, sorry. I've got parallelization inside my application that's never getting out, right? I've got four cores or eight or 64 or whatever, right? But it doesn't matter. I'm only ever gonna be able to use one because the OS is like, you only got one thread. What do you want me to do?  That's weird, right? You only get one core at a time. So I can't use multiple cores. The other problem here is that, well, there's something else that can happen, right? So the, so there are scheduling issues because I don't know if there's one thread. What's one thing, can you guys think about perils? If you guys have used P threads or some of those libraries, what can a thread and P threads do that can potentially bring this whole charade just like crashing down, right? What could I do in P threads that could just really, really cause serious problems in my application, right? I'm running along. I've got this fake pseudo thread that P threads has created for me. How could I cause the process to lose control in a way that could be really problematic? What if I make like a blocking IO call, right? So my little thread tries to do like a read or write. So what's gonna happen? There is no way for the threading library to intercept that call. I'm gonna make a system call. The whole process gets put to sleep until that read completes. The problem is it's possible that a bunch of the other threads inside that application could have actually kept going and done useful work. So to use threading libraries like this effectively in DOIO, you have to use these wrappers that the threading library provides that allow you to do reads and writes that ensure that the threading library gets control when you do that, right? So what's gonna happen is I'm gonna call, I don't know, P threads read or whatever, and it's going to say, okay, I'm gonna issue what's called an asynchronous read to the kernel, right? That's a different way of doing read that doesn't block the process. I'm gonna put you to sleep on my own little thread queue here. I'm gonna run a different thread, right? But if I make a blocking IO call, you know, that's a way to sort of ruin the opportunity to use user-space threading libraries to achieve concurrency, right? The whole process will block even if there's lots of other useful work that could get done, right? So there's some careful programming I need to do in order to get this to work, right? I just can't take a big blob of code that somebody else wrote and drop it into my, into mine. Although maybe P threads is far enough to like rewrite the C library wrappers of read and write to do the right thing. I don't know. Okay, there we go. So what's good about kernel, now we've talked about, you know, the pros and cons are clearly kind of related. What's good about kernel multi-threading? I mean, obviously I can use multiple cores. That makes me happy. What else? I can do IO in my usual way, that makes me happy. Any other things you guys think could be good about other than correcting the things that are bad about user-space multi-threading? One thing, and we'll come back to this next week, is that given more visibility in the process, it's possible that I can do better thread scheduling than the internal thread scheduler that runs in the user-space thread library does, the kernel knows more about the machine, right? It has more visibility into how the resources is actually being allocated. It might be able to do a better job, right? And of course the cons are, again, these are highly related. I have a context switch into the kernel anytime I switch between threads. So it's a little bit more overhead for using the multi-threads on the machine. All right, so, oh, thread states. Okay, I'll leave this online. I think you guys can, now that the slides are online, I don't have to get through everything every day. It's awesome. I'll just leave it as homework. You guys can look through this. This stuff's pretty intuitive. We'll start with it on Monday. What we're gonna do next week is start talking about scheduling, right? So we've built the mechanisms at this point. I have full control over the CPU. I can start and stop threads whenever I want to. I have this nice abstraction that I'm providing to programs for how to think about how to use the system effectively. So now, and again, we'll come back to this when we do memory and files and other things. Now we need policies that are gonna effectively make use of the system resources. So that's the topic of thread scheduling and CPU scheduling, and we will talk about that next week. So good luck with your site and two design documents. I'll see you guys on Monday.


Yeah, very simple. So we adjust conservation law of mass, continuity equation, momentum conservation, and energy equation. But the only difference is that there are two energy equations, because we separate them for electrons and for lattice separately, write them separately. So this is energy equation for electrons. And this is energy equation for ions. So what we have? We have a metal. So this is metal. This is his boundary with vacuum. This is vacuum or water or some transparent media. This is ions and electrons. And this is penetration depth for electromagnetic wave. For optical electromagnetic wave, it's typically something like 50 atomic layers. And now we radiate photons, larger photons, and they are absorbed only by electrons. So initially, we have equal temperatures for electrons and ions. But after heating, electrons become hotter, because they absorb energy. They absorb energy from this term. This is absorption term. And they transfer part of this energy back to the ions. But this transfer is rather slow. Its power is much less than the power of laser. If we use femtosecond lasers, we're very bright flashes. Therefore, they are much hotter than ions. And another important ingredient is this electron heat conduction term. In metal, it is large. And this term transport energy absorbed at the skin depth here into the bulk of the metal. So this is electron heat flux going into the bulk. And it creates some so-called heat affected zone near the surface. It also has nanoscale thickness. But typically, it is something like 5, 10 times more thick than the skin layer. So the skin layer is 10 nanometers. And the heat affected zone is something like 100 nanometers. And here, I just write some simple expression explaining why it is supersonic. In usual conditions, heating is much more slow than the sonic acoustic wave propagation. The velocity, the rates of the heat transfer is usually subsonic, significantly subsonic. But in our case, it is supersonic. Why? This is just due to the fact that the Fermi velocity of electrons which transport this energy is two orders of magnitude higher than the speeds of sun. Therefore, for some time, this velocity, just heat velocity, heat wave propagation velocity, it is larger than the acoustic velocity, which is small because the ion are heavy. Therefore, this heat affected zone is created supersonically. Supersonically means that refraction propagation. And we heat the system. Therefore, we rise pressure just because we rise energy. And we don't have time to expand, to release this energy, to release this pressure, to unload matter. We don't have time because it is supersonic. Therefore, pressure rise and matter became to unload to the vacuum side. And the refraction began to propagate into the bulk. But this heat affected zone is created before. So for a hydrodynamic picture, we just immediately create a heated and pressurized layer. And after that, follow its unloading. So we consider this problem. For example, it is a gold. It is typical situation in water. People illuminated by femtosecond laser. And this process produce nanoparticles somewhere at very late time, after pulse. But how it proceeds? It's still not well known. And we use this equation, just very simple hydrodynamic fundamental equation, to describe the unloading of gold. So gold is heated. It is unloaded into water. And what we see is, this is the pressure profile and density profile. This is density jump on the gold water surface. And it move into water, support the shock wave in the water. This is shock in the water. This is shock-compressed water. This is contact. This is refraction wave. And this is compression wave going into the bulk of gold. And this is refraction wave. So if it will freely refraction, it will be somewhere here. But water decelerating motion. And some layer appears. I call it atmosphere. I will explain why. Where the gold know about existence of water. Outside this layer, gold expand freely without any water. So this unloading produce motion of the contact. The motion of the contact, like a piston, produces shock in the water. And this is shock-compressed water. This is density jump. Because gold is 20 times more dense than water. And this is at the later time, we see this pressure wave. It is rather large amplitude. Something like part of megabar going into the gold. And the shock going into the water. And we produce this, this is condensed matter. This is, therefore, when we expand it significantly, it began to nucleate. It came to decay to small fragments. And this is region where it decayed. Later in time, this is sub-nanosecond stage. Shock goes far away. This is the contact. And here, so this is the contact. This is so-called atmosphere. It's motion is decelerated by water. Therefore, it moves more slowly. But this form region don't know about water. It moves freely. Therefore, it moves faster than the atmosphere. Therefore, it collides with atmosphere from this side. But the amount of mass in this form region is limited. Therefore, after some time, it just, all this mass go into the atmosphere. And after that, only vapor support atmosphere from the rear side. And here, I just show how it looks like. This is one-dimensional simulation. So here, this form region is like just fluktation of density. But this is three-dimensional molecular dynamic simulation. So you see this is atmosphere. And this is this form region for two-time instance. And this fragments of the form fall down. Therefore, the atmosphere becomes thicker. And also, the water is heated. The blue color, I mean, this is bulk water, deep blue. And this is light blue water, which is heated due to atomic-atomic molecular heat conduction in water. It is small. Two orders of magnitude smaller than in metal. But it is enough to heat water near the contact. And this is enlarged fuel. You see this form region, which is attack, this layer. And the temperature dropped down into the bulk. Therefore, the vapor pressure, also, a saturation of vapor pressure drops down as temperature drops down. Therefore, this is vapor. It is dense here. Temperatures are water of 7,000. Kill me, 5,000, 7,000, 8,000, something like this. Near 10,000. Therefore, it is dense here and this dense far away. Here, just I will show this move twice. Here, I won't just pay your attention to this how this form region too fast. So we have liquid fragments. And vapor inside the cavities. They move faster than the atmosphere. Therefore, in astrophysics, such process called accretion. So it accretes on this atmosphere. And why I call this layer atmosphere? Because it is decelerated by water resistance to motion. And thus, we have some effective gravity here. This effective gravity produce density and pressure drop in the atmosphere. Therefore, pressure here is higher than here. And this decelerate, this pressure gradient decelerate the atmosphere. And the shock in water propagate to large distance, up to millimeters and centimeters. And here, I just normalize it. And what I want to emphasize that even for large, very large, when it go far away, it amplitude decay. And it becomes just sonic wave, acoustic wave propagating in water. The bulk models of water is something like 2 GPA. So now it is 2,000. So it is 0.2 GPA. So it is in linear regime. But still, the pressure here and pressure at contact are somehow comparable. So it is 10 times smaller. But it is some 10% value of the pressure at the shock. So the piston contact here and the pressure shock here are connected. And this is how the decay of the pressure takes place. So this is time after heating, short heating. Heating goes very short. Just shorter than one picosecond. And after that, the pressure at the contact boundary fell down. And this is shock. And it decreases. But the rate of decrease is not so high because it is supported by the foam, which attack it and support pressure. But when the foam is exhaled, no more mass in foam. So this support decay. After that, it began to drop faster. But then it is supported by saturation pressure. This is the temperature of atmosphere here in kilocalvine. So it is thousands of Kelvin. And this is saturation pressure for gold. And we see that after this drop, it is supported by the saturation pressure, which is on the backside of the atmosphere. So at the backside, we have saturated pressure evaporated. And it supports the atmosphere, motion of atmosphere at this time interval. And these are velocities of contact, shock wave. And we take some analytical fit. It is necessary for us to calculate deceleration. Because if you numerically calculate it, it will be very inaccurate. Numerically differentiate velocity. And afterwards, we use this expression for lateral instability with viscosity. This is kinematic viscosity and surface tension. Both of the object is very small. It is just 100 micron in the lateral dimension. And in this dimension also, just few micron. Therefore, the scales are very small, just from 10 to 100 nanometers. Therefore, all this surface tension and viscosity terms become very important. And the acceleration we take from the previous, from this. So we take velocity differentiated obtained acceleration, put it here, and calculate the linear gain of lateral instability. So we have typically, this is typical capillary scale. And we have something like 100 times growth. Not large, but not also negligibly small. And the heat is how it developed. Now I want to pay, to attract your attention to this process. So it's just the lateral, damped by viscosity, high viscosity, damped by surface tension, but still it developed due to deceleration. We decelerate by less dense water. We decelerate very dense gold. Therefore, this is typical condition for the lateral instability. And it have time, and it have possibility to grow significantly produced with nanoparticles, which may be after that collected in the experiment. I just heat is the experiment. But it is a lot of such experiments. This is typical, we produce colloids of this very, very small particle, something like 10 nanometer in size. We use it for many application. And now I want to pay your attention to this part, how it developed in time. And this is molecular dynamic simulation with embedded atom method potential developed by Vasily Zhakhovsky for gold. And that's all.