Assalamu alaikum, I am Mokhtar Ahmad with the virtual university course human resource management that is management MGT 501 and we are here today for our lecture number 19. So we started last time the selection process and we are continuing with that and I hope you are getting the basic concept and you are able to go through your text to make sure that you are learning something. So today we are here as I said with our lecture number 19. So as usual we have to go back and try to review what we covered in our lecture number 18 or previous lecture. Let us start let us summarize quickly our previous lecture that was our lecture number 18. We started with the selection process and in selection first of all we try to understand what selection is and since that selection is after the step of recruitment so we define that it is picking from the pool of the candidates picking the right person and during that discussion we also discussed this part that it involves making the judgment and judgment not about the applicant. When I am looking about the person we are looking about the fit matching the ability, the knowledge, the skills, the aptitude of a person with the job for which we have to hire a person that was the important part of course everything is important but the main theme of that selection is that we have to make the judgment about the fit and about the match not about the personalities and then we discussed the steps of the selection process. Of course we saw that there are 6-7 steps and then we started to look at each individual and as I said at that time that those steps not necessarily that each organization should follow the same steps. Then different textbooks have discussed the steps of the HR, but if you look at them in detail and you will understand, you will appreciate that they are talking the same thing. Wedding change is possible but the philosophy is the same, the concept is the same. The first step was an interest in the job, sending the resume that is of course the recruitment. This is basically the whole hiring process. Then our initial screening, yes selection process start with the initial screening, who I have discussed here. Then the third stage was the second stage of of course the selection process and here the third stage the application blank, he has to application, official document, then selection test, next step of course, which we will discuss today.  After that medical exams, test, drug test and then final offer and placing the person for the job. Remember we discussed that it depends on the type of job we are talking and it also vary from organization to organization that how many steps they want to follow. The purpose is that you have to pick the best person, you have to understand if that match is being created or not, then organizations, people they use different techniques, different steps, but we should also always focus what is the bottom line. And the bottom line is you want to create a match of the abilities of that person and the requirement of that job or that of that organization basically. These are the steps we discussed last time and these were the basically steps and of course, we discussed the steps in detail earlier. And they were initial screening, you want to separate those who qualify from those who don't. Why you want to do that, do that because you don't want to waste your time and resources on irrelevant people, which even don't qualify for that particular job, which even don't meet the basic requirement for that particular job. We discussed that organizations, companies, they put huge amount of their resources, time, money is involved there in the selection process. So they want to make sure the right type of people should come in those different steps so that they should be able to pick the right person. Next up, we discussed the application form, and what was the purpose of this? This is a legal kind of document, the first initial agreement between the applicant and the organization, where we extend the format of information, organization collect from those applicant, and again reason is, of course, there are legal reason and of course, the convenience to. Legal issues, by signing that application form or agreement, the applicant is certifying that whatever information he or she has provided to you are correct in the best of his knowledge. And of course, also authorizing you to go for the verification or checking the background, the previous history, or even asking for the reference. And also he or she is willing to work in your organization under the kind of circumstances, rule regulations, and he or she will follow those things. So these are all things, and apart from that, it will be helpful for you to make a proper system, that you can shortlist on that base, you can screen, verify, check what is missing, what is there, and what extra he or she has. And mostly it is job related. So these were the topics, we covered during our lecture number 18, our previous lecture. So we are still in the selection process. So let us see what are the next. So next step is the employment test. Again it depends, what job are we talking about. If it is a senior level position, you might skip that part. You do not have to test a person who is already at that level of caliber of co-experience to offer a job at a professor level. You will not be able to do a basic test. But of course it is an initial level, your line manager level, or even middle management sometimes you go for different tests. We have seen that generally 3-4 important test types are taken, intelligence test is given, aptitude, ability test is given, honesty test is given, interest test is given. Then if you look at the international arena, around 60% or more than 60% companies, they use one or other form of employment test for their selection process. Even when you might have applied for the admission, you should have gone through the entry test. Now even in the education institution, the admission test is taken. And then based on that, your merit is made. This does not mean that the institution or the organization do not believe in your previous credentials. But still they want to make sure that they have the best. And the reason is the same. There are some technicalities, some things that may not be understood or understood in the interview. It is necessary to take a test for that. So that is why people go for the test. Now when we are using testing concept, testing techniques, some basic requirements are also there. In the basic testing concept, there are 2-3 things. There are things in your text, in books, there is validity, there is reliability. What is this? Give you a little bit of its basic concept so that you do not get confused in it. What is validity? A valid thing. Something is valid. What do you mean by valid? The test validity concept is used in that. That is, does this test matter what it is supposed to matter? Do you want to see someone's English? Do you want to see how good his English is? Can he write in English? Can he understand? Then let us take his tough test. That is a valid test for that job. You cannot take his driving test to test someone's English, right? Whatever test you are conducting it should have the validity. We call it test validity. What the criterion validity term is used in this text is used in that and there is engineered text. When we talk about a selection test, what does it mean? If a person is performing very well in that particular test, will it, he or she will be able to perform in the same way for his job? The test is demonstrated by showing that the test constitutes a fair sample of the content of the job. The content of the job is reflected in the test, so we call it content validity. What is reliability? In the simplest word, reliability is that if a person performs the same test, then he or she should be scoring the same type of marks. Then it becomes a reliable testing technique. So these are the basic concepts we should remember while going for the testing techniques. And to establish any test that it is a good test, there are three requirements for it. For any test to say that it is a good test, it should be standardized, it should have reliability and it should be a valid test. So we can say that test is a good test and that can help you and that is serving this purpose for which you are doing the test. Clear? Let's see what kind of test we are talking about when we are doing the employment test. As I told you in the beginning, there are some general intelligence tests that are called IQ, aptitude tests, personalities and interest tests and honesty tests. And who will design them? Of course the proper persons, the proper competent person, the HR personnel, who have their own subject area. Psychologists, anthropologists, they all sit down and design these tests. Designing of tests itself is a huge task because they have to keep in their mind to whether this test is a standard test. Is this a reliable, so valid test or what? I don't want to go in that kind of those details but just remember that organization might go for such type of tests. And again it depends. Some might go for only one type of test, some might go for all type of test or some might go for extra, some other test like performance simulation. You are being placed in a real situation where you work and then what you do is you sample and see how accurate or correct you are. On job, you have a simulation where you create a situation where you tell them how you will do it. Or even they will take you to a real place. If you want to keep a section, you can take it to the computer and see what is the speed of typing. So you are not only concerned here for the speed, you will also be concerned about the correctness. You will also be concerned about the speed of typing but whether the spelling or the words are correct or not. You are just typing a word in a line. So these are all things. In just a test, you can see the real work that is done with the sample. You can see how she can perform. After that, there are some assessment centres like you must have seen. When we apply for the forces, you apply in the army. They have their assessment centres. They pass you through the Mughalif test. You go for ISSP. There are some Mughalif assessment centres and they go for detail testing there. So that they want to make sure that they are not doing any mistakes there. How can you make sure that this person is honest? So let me share some ideas with you. Some guidelines are given in the textbook that if you want to check someone's honesty, you should ask them. Ask blunt questions, direct questions. Don't hesitate of asking those type of questions. And you should give him or her a chance to speak rather than you should talk. You will get as many chances as you want to speak. So even you can ask for the credit check. Check his history, check his accounts. And if he or she is using credit card, you will get an idea of his history. That will be a good indication to see the honesty of that particular person. There are many techniques of this type. You can check your reference. The people who he has worked with, you can go back and check their reference and ask them how good he or she is in the dealing with the people. Especially talking about the financial aspect and other aspects. Besides that, you can also check the test drugs. If he says that he has never said anything like that, but if he comes out of the test, that means he is not honest. He is telling you lying. So there are many activities like this that test designers do. They give you a situation. Let's see, this is the situation about how you react. So you can assess someone's honesty or work ethics. So this was testing for selection. As I told you, it varies from organization to organization and the type of job we are talking about. Let's move forward the fourth step that is the interviews. Interviews when you ask people questions. Why do you do this? And how does it happen? There are multiple interviews. Sometimes, of course, there can be one-to-one interviews. But as you move up and up, it is more towards one-to-one interviews. Sometimes. There are four people involved. There are managers and other colleagues. There are subject suppressants and technical experts. And basically, they are interested to look in those areas which are not clear from their application plan or application form. Those areas which you have provided with their resume or information, and especially it has to do with the behavioral part. So those things are not clear from there. You have to probe more and more about their behavior part. Like how much is their confidence? How is their personality? How is their speaking power? And if he or she will be a good team member? Or yes, you can also probe in those areas where you have some concern and issues. Like that flag we had read, you might remember. You can also see that in the questioning. And mostly, we are asking job-related questions in interviews. How many types of interviews are there? We can divide them into so many different groups. But let's see the few basic types of interviews. Unstructured, structured, and even sometimes people mix the both techniques. What are unstructured and non-directed? Where there is no pattern. And what is structured? Where there is a special pattern where questions are asked. Usually, when there is an interview, you are responding. So the interviewer is asking the same question to you. That is unstructured. And if he has a certain format, a question is being asked with a pattern. That is a structured interview. And it is good if you have a mixed approach. We will go ahead and see what is the basic philosophy of the interview. Methods of interview. One-to-one interview. Sometimes you can have one-to-one interview. And especially for the senior position, people go for the one-to-one interviews. With the people at the same level and even the people at the high level. Group interviews. That is also a technique being used. And sometimes you might have it to appear before a board. And as I told you, it depends on how many people are there on the board. Generally, it is seen that in a board, there are people with extender format. There are managers, top management, HR managers. Even psychologists there sometimes. And technical people are there. Technical experts. The experts of the area where they have to hire a person. And even people from the same section or branch where their job is placed. So that they should also become the part of their selection process. Because ultimately they have to work with them. So it is one-to-one. A group can also be on the base. And you can also conduct an interview in a proper board-beak form. Besides that, sometimes you put people under stress. Stress interview. If you have a chance to go for ISP, apply it in the forces. So over there, we usually create a situation like this. That you are tested under stress. And they want to see how you will react, how you will perform under stress. That is also one method of interviewing the people. Video tape interviewing would be there. Nowadays, new technologies are there. Even computer-based interviews would be there. Remember when we were talking about the human resource information system? And I said that you can use the same system for the interview. Nowadays, on the video website, on the computer website, in one city, in another city, in one share, in another share, in one country, in another country, people would be interviewing bad people. There would be a telephone interview. And different other techniques or methods are used for the interviewing purpose. There are some requirements to be effective for any interview. Do or don't have. You should do this or you shouldn't do this. Let's see what are those. If you want to take interview, if you are an interviewer, you do ask open questions. And remember we have discussed this open-end question and closed-end question. What is open-end question? What are the open questions? Open-end questions are those questions where you are giving the option to the person that he or she should speak more. As I had asked you at that time, if someone asks you what your answer would be if you had done the interview in the morning? Yes or no? That is a closed-end question. Of course, when you are doing the survey or when you are going for the research, you should ask closed-end questions. So that you can get an answer in a standardized form and you can compare. But the purpose of the interview is different. You want to judge others and take information from them. So the more he or she will speak, the better. So here the option should be asked the open-end question. Now what is the open-end question? If you ask the same question to the person that you had eaten in the morning? What did you use? Now you can speak more. If you ask the same question to the person that you had eaten in the morning, what did you use? I had taken red liti, fried liti, tea, coffee, liti and so on. If you are asking the open-end question, you are giving the option to the person that he or she will speak more. Because that is the basic reason of going for an interview. So first thing, do ask open-end question, open-end question. And mostly ask the job-related questions. Of course, sometimes you want to see their intelligence to be aware of the current affairs, how much their intelligence level is, how their human aspect is, how their team members are. So you can ask a little bit of irrelevant questions about what is happening in the market at this time. What team is winning at this time? Just to see whether their emotional maturity is that much. Because the new concept that is coming up today is that you will be also interested to see the emotional maturity of that person. It is not only the IQ. Even the more important thing is the maturity. So mostly, of course, you should ask the job-related questions. And this is also your responsibility as an interviewer. The interviewers should open the interview. And how can you open the interview? And of course, the interview is a big job interview. It is phobia. Even experienced people, when they are appearing for the interview, they are a bit nervous. Now, your purpose is not to make them more nervous and not even see what they want. The good approach for the interview is, you should put them at ease. And how can you do that? You have to open the interview. Welcome him or her. And the very common type of questions people start with, they are asking the person who is there for the interview, okay, tell us about you. It is the easiest thing to tell about yourself for this. If I ask you, okay, tell me about you, what you have done and what you are doing. Don't you think it will be very easy for you to explain? And so, as you start speaking, your confidence level will be good. And then it will be easy to talk with you. So, that is also your responsibility. If you are taking the interview or you are interviewing, you should open the interview. If you are with a nice word, so that the other person, the applicant should feel comfortable. So, what else? Do ask positive questions. Don't have the negative approach, because you are interested to see the positive side of that person too.  Also, look for the area where applicant is uneasy. If you are asking him or her, if you think he or she is feeling uncomfortable of responding to that question, something is wrong there, logically. Look at those areas too. You can ask more details about that. So, same way, there are don'ts. Don't do that. See the opposite. Don't ask all close questions. It might be asking one or two, but don't ask, because you have to do all positive, open questions. Open questions. Don't ask personal questions, it has to do with your, his or her job related things. And don't do all the talking. If you are going to take an interview, then try to let him or her talk more, because of which the interview is being taken. You should start experiencing all these things yourself. The interview is not yours, it is hers. Don't do all the talking.  If you have asked a question, then give it a chance. Let him or her talk. This is also a good feature of the interview. That he gives a chance to the other person because, again, remember, when someone comes for an interview, there is some kind of phobia. And don't ask more than one question at a time. Because they say it with questions, don't be impatient. One by one, ask questions. So, let's see, what steps should you take for an effective interview? You mean, the one who has to take an interview, be prepared before going for an interview. The one who is going to take an interview, he should also prepare for which job interview he is going to take. And how he has to ask questions. Because he has to compare so many different candidates. So, before going for an interview, one should be very well aware of the job description, job specification for which they have to hire a person. And that will be also your job to welcome the candidate. Show your concern that organization is very concerned and very pleased that he is interested to join you. Or she is interested to join your organization. She will gain confidence and will talk to you openly. Plus, even if you will not select him because she is not fulfilling the requirement, but still he will be satisfied that he was giving due respect and opportunity when he was with you people for interview. And your reputation in the market, do you know this? People go out and tell you what happened, how people dealt with him. So, you are doing the marketing part too. And as I said earlier, you have to encourage him or her to talk. Because that is how you will get some information from him or her. And that is how you will judge him or her. Encourage candidates to talk. Because you are taking the interview, you have to control the interview too. How can they do that? You understand, you have asked a question. Now, the person is now talking every relevant thing. So, you don't want to waste a lot of time there. So, it is your right. So, bring it back to the check. And who has to ask questions, all these things come into your responsibility. For a good interview, you control it yourself. Now, start interviewing him. And sometime, yes, you can ask him, do you want any information from our side? Do you have any question from our side? Because he might have some doubt in his mind about your organization, about the job, about the working environment. So, do provide him or her necessary information so that things can be more clear between you. And then at the end, you have to close the interview. And how can you do that? Of course, you have to thank him. Thank you for coming here. And you have to let him know that how he or she is going to know the results of the interview. You can tell him that, brother, you will get it later in the house. Whatever this scene was taken. You can check it by phone or on the web. We will get the results. Whatever. And thank him so that, even if he was not selected, or she is not selected, he will take good memories from your interview exercise. So, is it over here? No. You have to do one more thing. That is the final step. And that is, put everything, write down your notes. Because you have not interviewed one person. It is possible that you have to do 10, 20, 25. So, the memory of a person is up to a certain level. So, what do you know that when after 10, you start comparing people, you will forget what you asked him, what positive things he had, what negative things he had, what grading he had, what marks he had applied. When you have to go for the final selection, you have to compare all of them. So, you have some reference material. You can tell it based on that, no, person A is selected and B is not selected. So, this comes in the final steps. Write down your observation, your opinion, in your notebook, in your folder. And sometimes, yes, they also, most of the time they provide you the sheets. Where the rest of the food is made, the color is made, you have to do the grading, you have to apply the marks. So, you have to do that so that you can benefit from all the exercises. Some other guidelines. If you have different candidates for the same job and you have to compare, make the comparative things that, which one is better. So, it is suggested that you should mainly focus on the form of interview. So, that you can check them at the same parameter, all those people. Of course, it is not binding that you should not ask unstructured question. You cannot go for unstructured interview. Yes, sometimes mix is important, mix is better. And don't make quick decisions. Delay your decisions. Wait and see all those relevant information. Compare their CVs. Just don't make a sudden decision on the interview base. Good. And remember, you have to focus on traits that are more accurately assessed in the interview. Now, the traits that are already checked, like the expertise you have seen and the knowledge base you have seen in the test. So, here you have to see what is the motivation level and what is the personality and what is the behaviour aspect. What is the confidence and if the job is related to some kind of where he or she has to talk with the people, what is the speaking power. How good he is to pursue it if he or she is to go in a marketing job. So, you have to see what the job is related to. You have to focus on traits that are more accurately assessed in the interview like motivation to work and personal relationship. As a human how good he or she is to become the team member because nowadays organizational focus more and more on the team work. Individually if he or she is excellent but they are not good as a team member that is a negative aspect. So, this is also a good thing for the interview that you see that personality trait that traits that can be helpful in the job. Sometimes he comes to let him speak get the interviews we do talk because the more he or she will talk the better chances it will be for you to assess him or her. Or in this you have to think about the legal aspect that how, as I told you don't ask the person question. This is a country where privacy is said that some information some things are your personal things your family, your life your liking, disliking but again it depends in some places, in some countries under some laws they are protected that you don't ask them these type of questions. So, you have to think about these things but sometime we do mistakes in interviews. So, here I will discuss the common interviewing mistakes. This is embarrassing so the interviewers are embarrassed that what has happened. That is a problem. Problem for what? Problem for organization problem for that person and even problem for society. So, to avoid embarrassment those mistakes become less and less. So, interview is good selection process is good. Let's see what are those common mistakes. Snap judgment quick decision I am not saying this but but but but but but but but but but so making snap judgment quick decision you might be doing mistake negative emphasis some people approach negative that they forget positive things again you have to remember that you are not making judgment about the personality you are making the judgment about the match or fit so you should have all the time facing in your mind not knowing the job that is the common mistake we can see in even our organization today in our society many times those interviewers who don't have any problem about that particular job let's see if I am a selection board though with my name it is also Dr. Mukhtar Ahmad but we are there to select some orthopedics some heart specialists now what can I imagine what I have to ask them of course I can just maximum judge I can see their personality I can see their confidence so I don't know about that job I don't know about that profession that person who wants to hire what he has to do so this is a common mistake we can see in our society especially in our country that irrelevant people who don't have any job who don't know they are selected so you can also imagine how many mistakes there are what other mistakes common mistakes we can see pressure to hire now what kind of pressure are we talking one pressure is that when a profession has pressure that they need to hurry because they have to start their work in that hurry they are quick judgment about the mistakes sometimes this pressure is in our society that we have to keep this we have to keep this in favoritism how much pressure as you remember when we were studying there was a blind box I told you people don't want to be don't want to show their identity while they are advertising for the job because one reason I told you that you have pressure from different sides different stakeholders they pressurize to keep this and again this is a mistake this is dangerous for institution even for that person too because he or she will be underutilized so pressure to hire if this is too this is a mistake which we commonly see candidate order error this is also very common kind of common mistake we can see in our selection process or interview if you are taking an interview 2-3 people come which are just average person their personality their appearance their presentation their skill their average and suddenly the next person is a little better but not of the best but since recently you saw he was an average person you liked this person and you think this is the best it can be other way around 2-4 very good people came to you and suddenly the average person of that level you will ignore that you have so many good thoughts this is still better but if it is other way around if the order in which people are coming 4-5 which we call knowledge which doesn't qualify even they are below average if they are taking an interview and suddenly the average person comes to you then you will definitely compare him from the past but he, she might not be the best because you are comparing them with that reference according to the order this is also a mistake when you are taking an interview and sometimes non-verbal behaviour can also affect your interview process what is non-verbal behaviour? can you even deny anything someone's non-verbal behaviour? and someone can favor you with that what style is he talking about? what is his gesture and generally these things can also affect the disson and this is also a common mistake let's move forward there are certain other things which can also affect your interviews for your interview which is called negative effect what are those things? impression management from both the sides the interviewer and the interviewer can also create a bias effect let's see if you are taking a very tough macho man you are a very tough interviewer so you understand impression management impression management is a technique basically in the organization where people want to control the perception of other people when they are perceiving something about you the other person who thinks about you or perceives you you want people to think about you so the behaviour you adapt to that is impression management if you want to give a wrong impression this is very tough you can just throw people out so this will be a bias similarly if a person who is there for an interview he or she is smart enough her personality is also good so she will impress you and you pick the wrong person there is a bias so because of impression management things can go wrong similarly the interviewer if his memory is not correct either way the few questions he asked he answered wrong and suddenly one or two corrects he will understand that everything is fine from the beginning he is getting better and suddenly a negative he is not a good person so this can also be a bias and generally people first do a few minutes do a few interviews if a good person comes in the beginning then it is fine again this is a bias so we have to be careful when we are doing the interview there are more effects again biasness can also come prior knowledge you already know that the candidate his positive are negative sides so this is also going to influence your interview process stereotype if you have you know what is stereotype when you judge a person based on which group he or she belong that is stereotype then you will influence your interview process order of interview is important yes as I told you in the beginning or the average person comes and starts to get bad so that is also going to effect your interview and the way information is presented is also important and that is also going to influence your interview process or interview decency negative things always get high weightage if some negative thing is presented in the interview you have seen some negative aspect his attitude, his personality his behavior so he has seen that all those things are superseded which are good so this also effect your interview but I think enough for today right so still we are in the selection process let's quickly go through what we covered today we discussed 2 parts today implied test in that we read the basic testing concept test type we saw and then we talked about interview interview guideline we discussed what is next now so next of course we are still in the selection part I will try to finish selection part and then go to the socialization part 2 in next lecture that will be lecture number 20 so let's stop it here so before I go as usual I have to inform you I have to tell you again that you have to work hard read from the beginning listen to the lecture read again and if there are certain questions there must be certain questions in your mind and do ask them send us mail write to us and we will be more than happy to answer with that thank you very much assalamu alaikum


In this video, we'll work through two examples of finding areas of polar curves. Consider the cardioid r equals 1 minus cosine of theta. Let's find the area of the region in the first quadrant within this cardioid. So let's get a sense first of what the curve looks like. Here's a graph. And the part of the polar curve that I'm interested in finding the area of is just that first quadrant piece. So one of our tasks is to identify what our limits of integration are. We know from earlier in this lesson that the area of a polar curve is the integral from theta 1 to theta 2 of 1 half r squared d theta. So we have our r, which in this case is 1 minus cosine theta. But the question is, what are our limits of integration? Well, the initial theta would be zero because that's the theta value where my cardioid begins being graphed in the first quadrant. It then enters the second quadrant at theta equals pi over 2. So our limits of integration will be zero to pi over 2. So we have our region that we're interested in. And we integrate from zero to pi over 2 of 1 half r squared d theta. Now r was 1 minus cosine of theta. So I'm going to expand that 1 minus 2 cosine theta plus cosine squared. Now in order to make this integration that much simpler, I'm actually going to use one of my trig identities, knowing that cosine of 2 theta is equal to 2 cosine squared theta minus 1. Knowing that, I can solve for cosine squared by adding 1 to the other side and then dividing by 2. So I have 1 half times 1 plus cosine of 2 theta. That expression is a bit easier to find the antiderivative of.  This gives me 1 half times the integral from zero to pi over 2 of. I have this 1 half here. I'm going to add that to 1. That's 3 halves minus 2 cosine theta plus 1 half cosine of 2 theta. So we have this expression. And we integrate 3 halves theta minus 2 sine theta plus 1 fourth sine of 2 theta from zero to pi over 2. And that gives us, I'm going to distribute this half across. I get 3 fourths times pi over 2 minus sine of pi over 2 plus 1 eighth sine of 2 times pi over 2, which is pi. Now if I substitute 0 in for each of these theta's, I actually get 0 for this entire expression. So minus 0. And I get ultimately 3 pi over 8 minus 1 plus 1 eighth sine of pi is 0. So that's my area of the cardioid in just that first quadrant. Let's now consider the area of the region inside the cardioid r equals 4 plus 4 cosine theta and outside of the circle r equals 6. With any of these types of problems, we'll need to find the points where the two graphs intersect. One approach is to equate the two equations and solve for theta. But this won't always work, because while the curves may pass through the same points, they may not do so for the same theta values, or quote unquote at the same time. It's always a good idea to graph the curves and further investigate where the curves actually intersect. So let's take a look at the curves. The circle is pictured here and the cardioid here. And I'm interested in the area of the region inside the cardioid but outside the circle. So I'm looking here. So ultimately, I'm looking for the theta values where the two graphs intersect. So let's take care of that first. 4 plus 4 cosine theta, that's my first r, is equal to 6, or my second r. Let's check out when that happens. So I get 4 cosine theta equals 2, or cosine of theta equals 1 half. Now between 0 and 2 pi, this occurs at pi over 3 and 5 pi over 3. While we may want to put these as our limits of integration, we also recognize that the direction of these curves as their graphed as theta increases, these points of intersection don't align with that. Oftentimes what we need to do is rewrite our thetas to align with the order at which the intersection points actually occur in graphing the two curves. 5 pi over 3, we can also express as negative pi over 3. If we think of the theta value as sweeping between negative pi over 3 and pi over 3, that actually aligns with the graphing of these two curves. If we were to integrate from pi over 3 to 5 pi over 3, we'd be looking at areas in this direction. So we have our limits of integration. So here again, we have our little graph. We're interested in this area, where our theta here is negative pi over 3, and theta here is pi over 3. And I ultimately want to find the area within the cardioid but outside of the circle. So the area of the region can be obtained by subtracting the areas of the cardioid and the circle. So I'll take the area between negative pi over 3 and pi over 3 of the cardioid, which is 1 half r squared, which is 4 plus 4 cosine theta squared, and subtract out the part of the circle that we want to eliminate, because all we want to do is be left with this outer piece of the area in the cardioid. So the area of the circle between negative pi over 3 and pi over 3 is the integral from those bounds of 1 half times r, which is 6 in this case, squared. Let's expand this. We have integral from negative pi over 3 to pi over 3 of 1 half times 16 plus 32 cosine theta plus 16 cosine squared minus integral from negative pi over 3 to pi over 3 of 1 half times 36. Now because these integrals have the same limits of integration, I can actually combine them. This is negative pi over 3 to pi over 3 of 1 half times 16. We get 8 plus 16 cosine theta plus 8 cosine squared minus 18. We further clean that up, negative pi over 3 to pi over 3, of negative 10 plus 16 cosine plus 8 cosine squared. Change colors here just to make things a little bit clearer. Negative pi over 3 to pi over 3 of negative 10 plus 16 cosine theta plus 8 times the identity we used in the previous example, which was 1 half times 1 plus cosine of 2 theta. And that gives us integral from negative pi over 3 to pi over 3 of negative 10 plus 16 cosine theta plus 8 times 1 half times 1 plus 8 times 1 half times cosine 2 theta. We're going to clean this up a little bit from negative pi over 3 to pi over 3 of I have negative 10 plus 4, so I get negative 6 plus 16 cosine theta plus 4 cosine of 2 theta. Now the nice thing is we have some symmetry happening. We know that the polar curve, the cardioid and the circle intersect when theta is pi over 3. And negative pi over 3, we all can also recognize that there's some symmetry here. I could find the area of just this upper portion above the polar axis and double it. So I'm going to do that here. I'm going to multiply the integral from 0 to pi over 3 of our function plus 4 cosine of 2 theta by 2. I can't always do this. This one is special because of the symmetry that's involved in this region. And I would get exactly the same result if I were to strictly evaluate this integral. But for purposes of simplicity, we're going to multiply the integral from 0 to pi over 3 by 2. So let's integrate. We have 2 times negative 6 theta plus 16 sine theta plus 4 divided by 2, which is 2 sine of 2 theta. I divided by 2 to compensate for the chain rule that I would use in differentiating sine of 2 theta. This is from 0 to pi over 3. So I have 2 times negative 6 times pi over 3 plus 16 sine of pi over 3 plus 2 sine of 2 pi over 3. And then we recognize I would, of course, using fundamental theorem, I would subtract this function evaluated at 0. But what we notice is that value will be 0 because negative 6 times 0 is 0. Sine of 0 is 0. Sine of 2 times 0 is also 0. So this is our value. And that's going to give me negative 12 pi over 3 plus 32 times root 3 over 2 plus 4 2 times 2 times root 3 over 2, which gives me negative 4 pi plus 36 over 2 root 3, ultimately leaving us with negative 4 pi plus 18 root 3 as the area inside the cardioid but outside the circle.


All right, welcome back to operating systems. So today, you should have what you need to start Lab 4. After today, you can start Lab 4 and save like 20 plus hours. So I will show you how to use UContext in Qs. So before we get into that, first, let's complete our diagram of a process. So here is what a process looks like with four threads. So each individual thread would have its own registers and hopefully independent stack. All four of the stacks in this case live in virtual memory. And what else is in virtual memory? Well, the heap and all global variables. Then other than that, besides threads and virtual memory, the process just has a table of open file descriptors as part of it, which we will get to whenever we get to file systems. But this is our more or less complete picture of a process with four threads. So any questions about this? All the threads live within the process before we just had registers in the stack. But now, we can include them as part of the thread. And by default, there would only be one thread instead of, in this example, four. All right, we're good, we're good, we're good, all right. So all this code is available to you that I'm doing today. You might, if you haven't looked at, the other examples, you might want to look at these examples. So they're in that materials repository. This is clickable. And specifically today is lecture 18. So that's where you'll find all of your code examples. So again, after this, I've updated description of lab four and stuff. So it will walk you through how the test infrastructure works, how to write your own tests. And then after explaining a really basic test, it explains a more involved test. So hopefully everything will make much more sense than lab three. So let's get into how to use a U context.  So a U context, basically it's just a structure of like all the registers of your thread.  So if you are implementing your own user threads, which guess what you're doing in lab four, this will do most of the heavy lifting for you. So it is very good to understand how these functions work. So let's walk through the code. So at the beginning, I just define a bunch of includes and say what I use from each of them for you. We only really care about this U context today and these are the functions you are going to have to use. All the other ones are just helping me and doing things to make your life a bit easier. Like this Valgrind stack register. Turns out Valgrind does not like what we are about to do. So you need to be placated somehow. All right, sirens are really close, nice. So I created this, are we in trouble? No, okay, we're good. I'm hidden for another day. All right, so there is this die function. So it just saves error know that I've been doing pretty much this whole lecture, prints an error message and then otherwise exits with whatever the error know originally was. And for lab four, you should not have any fatal errors. This should only happen for debugging purposes only. Or if something really goes wrong like you've ran out of memory. So I define a function for you called new stack. You do not have to read it, but if you were to read it, well it basically just gets some virtual memory of length this stack size and your stack is always going to just be this size. It's just a default size that we want to use. So it will check for error messages for you and then it will register with Valgrind. So you can check your code for memory leaks using Valgrind. You need to, turns out Valgrind does not like when you use other stacks and start executing stuff. So without this, Valgrind will give you like pages and pages of errors that aren't real errors. So just use the new stack function then you can use Valgrind all you want. Then if we have a new stack, we should have a delete stack. So here's a delete stack that does pretty much exactly what it should do. You don't have to read the details of it. Then here, so for this program we're going to create three threads. We're going to create thread zero, thread one and thread two. So we're going to create three UContext variables and the UContext structure is basically a structure that has all of the registers in it and saves you lots of hassle with trying to deal with saving all the registers and writing pages of code. That really doesn't do that much interesting. So after that, I declare globals for two stacks, a stack for thread one and a stack for thread two. I do not declare a stack for thread zero because I'm going to just use whatever the stack is that started executing main, like the main kernel thread stack. I'll just use that for thread zero. Yeah, sorry. So char is just like a byte. So this is just a pointer to a byte so that will represent the start of the stack. So char pointer or void pointer, doesn't really matter pointer to I don't know or pointer to char which if you go at the definition should be a pointer to a byte. Same thing just turns out that the types that the libraries we're going to use want to be char and char stars, but it's just a pointer. It represents a stack. So it could be void. They just decided to be a char pointer for some reason. Don't ask me why, but don't worry. Just use char star and it's just an address and it won't give you any compiler warnings. All right, so here is our main. So we'll start off by doing a get context call. So what get context will do is whatever thread is currently executing right now, it will save all of its registers to this structure. So it will populate it with the values of all the registers of whatever is currently executing. And it will also play with the program counter back such that that if we try to restore that state again, t zero u context will resume here. So it will resume like it just called get context and keep on going. So the next thing we will do is ignore the comments for now is the counterpart to get context is set context. Or if you want to think of it in a different way, sets context will restore the registers from whatever this structure is. So if I do a set context here to thread zero context, well, it will restore it to whatever the last call to get context was, which in this case was here. So goes here, prints or goes here, then execute set context, then goes here, execute set context, goes here, execute set context. I probably did something really bad, right? So let's do a print statement. Oh, no. So if I do this, this looks pretty bad, right? What do we think will happen? Probably just print, oh no, over and over and over again, which is a fun way to infinite loop ourselves. So there we go, prints, oh no, over and over again, because it's just going to set context and then restoring whatever these values for all the registers were, which brings us back to here, and then prints and no, does the same thing goes over and over again. It's a fun way to give ourselves an infinite loop. So doesn't this sound exciting already? Yeah, all right, groans, perfect. All right, so let's do something fun here just to see if we have any questions. So create a variable called x, then we do that get context. Let's do something fun. Anyone want to hazard a guess as to what will happen here? So print oh no one, and then just oh no one over and over and over again. Oh no one over and over again, we all agree. Whoops. Did I not compare, I don't think I saved it. Hit capital W, whoops, ah, stop. Oops. Anyone care to explain that? So what happened? Hmm, yeah, so if I do int x, where does x live? The stack, right? So here, basically what this is gonna do is bump the stack up four and then use that memory for something, for x. So bump the stack up by four and then write the value two, or sorry, write the value zeroed there. I don't know why the hell I said two. And then it's gonna save all the registers to this context, including the stack pointer. So the stack pointer is also going to be safe to whatever it is. And then here, I increment x, which is like, hey, I'm going to load it from memory and then increment it in a register and then I'm going to write that value to memory. So this would change the value of x on the stack, which lives just in virtual memory somewhere from zero to one. Then we print off whatever the value of x is, which in this case is one. Then we do a set context, which goes back here and stack pointer just gets restored. In fact, it doesn't change at all. It's still pointing to the same thing and we don't even really care that much. So x lives in the same place, so its value was still one. So we increment it, it goes from one to two, then we print two, then set context again, increment it from two to three, that the da keeps on going like this forever. Sorry, any questions about that? Yep. Well, yeah, if you put it in the stack, or sorry, if you just put on a register and didn't use a stack, then sure.  You could declare it as register in, oh god. All right, geez, why? There. Not a fix, do not use a keyword register at all unless you really need to. I guess you could use it for this. Anyway, yeah, well, so if I declare a variable in C, it just lives in the stack, so the C standard has to respect that. So is there a way I could make this always print one with just moving a single line of code? So what happens if I do that? So should I have it increment over and over again or will it always print one? Hopefully one, let's see. So that time it print always one. Why? Well, at the beginning, we didn't do anything. We saved whatever the stack pointer was, which had nothing. Then here it would have grown the stack by four bytes and then wrote that value zero there, then incremented it from zero to one, printed one, and then then it set context back. So the stack pointer got reset back to its original spot. Then it would have created space for an x or an int, so it would have used the same memory, wrote zero, so there still would have been a one there, so it would have written a zero and then incremented it from zero to one, then printed one, done it again and again, yep. So in this case, this will not overflow the stack because it keeps on resetting, allocating four, resetting, allocating four, resetting, allocating four. So this way, as long as this would go on forever, it would not run out of stack space. Because it's doing the same thing every time. Yeah, the stack pointer doesn't really matter. That same value is there anyways. It's just in this case, we're manipulating the stack pointer, but it would be the same thing if we just moved in x up here. It just wouldn't mess with the stack pointer, but memory would still be the same. All right, so that's fun. So let's see what else we can do. So I can delete that, let's get rid of that. So let's see how to create new threads that start executing something we actually want. So let's create thread one. So we allocate a stack for it, then to initialize that you context structure, even if you're going to overwrite some things, you still have to call get context to overwrite it. So we call get context initialize t1 context. So right now, if we did a set context, it would just return right back here using the original stack. But here we can play with some of the fields. So in order to change the stack for this thread, we can modify the UC stack field and it has two other subfields. So there's SS underscore SP. So that is the initial stack pointer. So you initialize it to the start of the stack, which is whatever you get from new stack. And then you have to tell it how big the stack is. And then after that, you can do a make context call. So make context will properly figure out what register represents the stack pointer depending on your specific hardware. So you could just do this on a Mac even if you wanted or an ARM processor. And then it will initialize this you context. So it will set those fields, fix them up, and it will also change the program counter such that it starts executing this function you give it. So in this case, I'm going to tell it to execute t1 run. And then I can also give that function additional arguments. If I want, it kind of gets kind of ugly. So I can say how many arguments I want to pass it and you are only allowed to pass integers. So here I will pass a single integer just to show you how it works. And I will pass a single integer with the value 42. And I have to do this ugly cast because C does not like this. So now if I do this, if I do a set context to t1, it will, it has been reinitialized here as part of this make context. So it has its own stack and it wants to execute t1 run. So it would swap everything over, start executing this function with a new stack. So here it should say, hooray, got arg zero and then print off whatever the argument was, which hopefully should be 42. So everyone agree with that? Hopefully, if I didn't lie to you, it will do any thoughts of, it will do something really weird after the printf, like what happens after it reaches here? Who knows what it does? All right. So this case looks like it just kind of ends. So we see we got our argument, it was 42, and then it reached to the end of this function. So by default, if a new thread from make context returns from the function it executes, it will just end your process straight up, which will not be good if you want to have other threads start running. So there are two ways to essentially combat this. You could have this do some type of cleanup at the end, or there is a special field in the U context called UC link. And what this will do is change that behavior. So if you set UC link, it will essentially do a set context whenever this returns. So to whatever UC link is. So in this case, if I set UC link to T zero context, it will do a set context there instead of ending the process. So that is all I did is I set, sorry, I set this line. UC link is thread zero context. And remember the thread zero context, well, currently that would be the last time that called get context and that would be back here. So if I run this, what should probably happen? Probably fairly bad things. I infinite loop myself again, but now I did it through two threads. That's fun. So what happened there? Well, I initialize get context for thread zero here. So if I do a set context on thread zero U context, it would resume here. Then here I create a new thread or a stack for thread one, do to do. I set it's UC link to go back to thread zero U context. I tell it to execute thread one. And then I do a set context to thread one. So now it switches over the stack and everything, starts executing this function prints. And because UC link gets set, well, it does a set context to thread zero, which goes back to here. So it just recreates everything, goes back, do to do infinite loop again, but with more steps. Isn't that exciting? All right, so that's exciting. Let's see, what else can we do? Yes. Yes. Okay, so let's see the rest of this program. So let's get rid of the set context. So let's instead of doing a set context or anything, let's make a less ugly one. So we'll just create another thread called threads two, give it a new stack, initialize it with get context, set up the UC stack parameters, then we will do a make context. So T two U context will run T two run, and we give it no arguments. So now, if we uncomment this, what should happen? Well, set context should go, it should start executing thread one, print off, and in this case, it should just end here because I did not set UC link. But if I did set UC link to go to thread two, well, at the end of this, it's like saying set context to thread two, then we would start executing this function. It would print off thread two should now be done, switch back to thread zero. So it would delete thread one stack because now that thread has terminated, we can safely delete it stack. Then we set context back to thread zero, which, oh no, goes here, which probably looks bad. So if I do that, I should have our third infinite loop of the day, that's even longer. Yay. All right, so what I would like to happen is if you're doing threading libraries, you probably want thread zero to resume from wherever it did it set context from, right? You probably want to come back immediately, not come back to the very beginning. So there is this better function called swap context, and this will save you a headache. So I could have told you to essentially implement this yourself because what it does is it does a git context of t zero context. So does a git context of its first argument, and then it also does a set context of its thread one argument. So it will essentially save the current progress that it is currently at into this u context and then do a set u context of this. So if we do a set context on thread zero, it looks like it resumes right here.  Technically, you don't really need it. I could have been mean and not given it to you and let you waste like five hours implementing it yourself. So basically this swap switches from t zero to t one, or does it go the other way? So it does a git context of thread zero, the first argument. So it saves that and then restores this u context. So it switches to that and then if it comes back, the t zero u context would resume back here. So in this case, if I do a swap context, t zero should resume here. So I set context over to t one. So it should go ahead print here. Then this function exits. And because I set uc link to thread two, thread two should start executing this, which deletes thread one stack. And then we set context back to thread zero, which should resume here. Then it should print main is back in town and then delete thread two stack because it is now terminated as well. And then it should return from main, which would exit the process. So in this case, I should actually see three print lines and nothing bad should happen. It should terminate successfully. Yeah. Oh, so I mentioned uc link here. Okay, so yeah. So any questions about how that works? Sorry. Yeah, so well, these are threads. Yeah, so any questions about that looks good. All right, so fairly, well, without swap context, it's fairly easy to infinite loop yourself. Thankfully you get to use it. So hopefully you don't infinite loop yourself, but if you do, you'll get into this situation. So this does all the heavy lifting for you for lab four. You basically just have to maintain a queue of threads and then do some stuff. So you can switch between them, make an exit, make a join. You're just adding stuff on top of it, but all the heavy lifting is done by ucontext for you. So, so make context. So make context, you can, first you have to initialize this ucontext through a get context and then you're allowed to change things. So I can change the stack and then make context. All it really does is change the program counter such that if you do a set context, it will start executing that function and it will do some things to make sure arguments get passed to it as well. All right, so we're good. We can figure out how to use a list. All right, so here is a quick way of using a link list so you don't have to implement your own. I highly suggest you do not implement your own because if you screw it up, especially with threads, you'll be debugging for like another 10 hours, which is more than you should spend on the lab. So use this. So this is the first time you should be having to use a link list in the labs. If you have not, you probably shouldn't have used the link list, so here we go. So there is a sysqh and it has a bunch of fun things in it that will let you create link lists. One of the link lists name is this tail queue and it's a weird name. All it is is a doubly linked list. So how it works, the queue you will need in lab for is just a ready queue or a waiting queue. So it's just what threads want to execute. I do not suggest you like having a link list of thread control blocks or something like that. All you need is the IDs of the threads, whoops.  So all you need is an ID of the threads. So just have a link list of ID and then this tail queue entry macro, it needs as an argument the name of the struct it lives in and then just any old name that it will reuse for other macros, you just have to be consistent. You can call it whatever you want. This case I call it pointers because essentially, because this is a doubly linked list, it will initialize a previous and a next pointer for you without you having to make it, without you having to use pointers at all. The next macro is this tail queue head. So it wants a name of a structure that it will create for you and then it wants to know what this list will hold and it's just the name of the struct of whatever the elements of the list are. So after that, it will create a struct called whatever this is. So in this case, I just called it list head that you can create variables are and of and it represents a list. So here I'm creating a list called list head as a global variable. Then the nice thing about it is it has macros for iteration too. So if I wanted to print all the elements of a list, I could just print off the list, then create a pointer to a list entry and then I use this tail queue for each macro that will do a for loop for me. I don't have to, you know, go to the next pointer, go to the next pointer, check if it's null exit. Don't have to do any of that. Just use tail queue for each. It needs a pointer that it updates and then the address of the list. So in this case, it's just the address of that global I defined and then it just needs a name of the pointers that I used up at the top. Then after that, every iteration of the loop, this element will just be the next element. So it would print off the first element and then the second and the third did the done until it's over. So don't have to play with pointers. Again, don't play with pointers, especially in this lab, you will probably mess it up. So if you want, there's other ways to access elements of a list. So there's tail queue last. So you just give it the list and then the name, the structure of the list and it will figure out how to get the last element of the list for you. So if we wanted to print off the ID of the last element, this is how we would do it. We should probably check that in the case, the list is empty, this would just be null. Okay, so let's go through main and see how to use it. So to initialize your list, you just use tail queue init and then give it the address of the list. And then here, I'm just asserting that my new list is empty. So you can go ahead and use that. Might be useful for you in lab four, if this is supposed to represent a queue of threads to run. If there are no threads to run and some thread just died, probably means there's nothing to execute, which probably means you should terminate the process. So let's see how to add things to it. So I will declare a entry on my stack. Obviously this will not work for your code because while you're probably going to have to share that between all the threads, so you're probably going to have to malloc this. But in my case, I just put on the stack just because it's easier for me. So here I set the ID to one, then there's tail queue insert tail. So this will put it at the end of the list. You give it the address of the list, the address of the entry to insert, and the name of the pointers that you used in the macro way above. So here I print off that I inserted it, then print the contents of the list. Hopefully it's just one. Then I create a new entry for ID two, insert it at the tail. So I insert it in the back. You can go ahead and use the man pages. So man, tail, queue and knit. And it will tell you all the other functions you can do in this. So you might find some of these useful. So for instance, if I wanted to, I could insert it at the beginning of the list with insert head. I could see whatever the thing at the beginning of the list is with tail, queue, head. There's all these functions for you. Do not write your own pointer manipulation. So here I say insert two. If I print the list, hopefully it has the elements one and two in that order because it should be at the back. Then I'll also print last element should be two. Then here I can use remove. So I give it the address of the list, give it the address of the element I want to remove. And again, that name. So I removed one. So hopefully when I print the list, whoops, that is the wrong example. It is called tail queue example. So here I inserted one, my list has one. Inserted two, my list has one, two. And the last element is one or two. Then I removed one. So my list just has element one in it. So fairly straightforward how to use this. Any questions? Use this. This also makes it easy that if you wanted to change it to like a singly link list for whatever reason, there is, I forget what the name, I think it's called S list queue or something like that or S list. I think it's just called S list. So if you want to change this to be a singly link list, just change tail queue to S list and boom. You don't have to change anything else. It's now a singly link list because of the magic of macros. So that would make change this so that it only has a next pointer that it makes it really easy to change the implementations if you want. Yeah. It's called tail queue. Why is it called tail queue? Tail means you can access the back of it. So normally singly link list is just the front and then you have a point of the front. Call the tail, I don't know why they called it the tail queue. That's my best guess. All right, any questions about that? Again, use this and also that S list I talked about. Well, you will have to read it for lab five anyways. So you should probably just get used to using this because you'll have to read it eventually anyways. All right, any questions what we did so far? Other than that, I'm going to ask you a question and test your knowledge. No, good? Sure, like the conference. All right, so here is basically an exam question that was, I forget what year it was. So what this question does is create some global variables so it creates a global int called I, what creative names we have and initializes it to zero. There's also two U context. So there's U A, which is initialized to execute thread the function thread A. So U A wants to start executing here and then it also initializes U B, whoops. Then also initializes U B that wants to start executing there. And then this question says U one kernel thread that does a call to set context, which again shouldn't have a space here to thread A. And then it asks you what happens, what do I see printed or just what happens in general. So I will leave that with you for like a minute, have a good think about what the hell this does and let's see if we are correct. All right, we have any good guesses? All right, do we agree with that? So the argument, we will see A one, B two, A three and then B terminates and it's done. Yeah. For a B end, it should start at that line. You see link was not set. Which is to be D should be one, no? Yeah, D is one. All right. And if we switch back to A, it would get that it's condition gets different. D is not one. Okay, is there any other thoughts up to what it does? Or are we all agreeing? Okay, so, all right. Well, let's just go through it to see what happens. So thread A starts executing and has its own stack. So in D here would declare AD on thread A stack. It would be a local variable. So here I will just put off and it would initialize it to zero. So now thread A would check the condition, the while loop. So the current value of I is zero. Zero is less than three, at least in this world. Then it will increment B here and increment I. So the global variable I will change from zero to one and then it will execute the print F. So it will print A one and then it will change the zero to a zero because it sets the value for D and then it does a get context call. So when it does a get context call, if we do a set context of UA, it will resume right here. So next thing it does is check the value of D. Current value of D is zero. So it would go ahead and set D to one and that's it's D which is currently on its stack. So then after that it does a set context to UB. So we start executing the purple one over here and it would have its own stack. So the first thing thread B does is declare AD on its stack and it writes a value of one to it. Then we'll check the while condition on this side. So in this case, what is the value of I? One. So the value of I is currently one. So one is less than three. So it will increment I from one to two. There's where that two comes in and then B will print B two. Then thread B will change its value of D from one to one and then call get context on UB. So UB will move here. Then it checks the current value of D. So the current value of D is one. So it would go into this if and then it would change the value of D on its stack from one to zero and then it would do a set context to UA which would change the stack back to A stack and it starts executing right here. So if we switch back to it, the value, it doesn't get context, doesn't save the values on the stack at all like we saw before. So the current value of D is what? The current, so the current value of D is one. So we would not go into this if branch. So it would go here then go check the condition of the while loop again. So what is the current value of I? Two, two is less than three. So it would increment I from two to three.  Then it would set its D back to zero and then do a get context call which doesn't move it at all. Check the value of D which is now of course zero and then it would change it from A zero to A one and then do a set context to UB. So UB would resume. So what is the current value of UB's D on its stack? Zero, so zero is not equal to one. So it will go back, check the condition of the while loop is three less than three? No, it is not. So it would exit here or it would drop out of the while loop, exit return from thread B and assuming you see link is not set it just terminates the process and we're done. And spoiler alert, this kind of looks like what would happen in swap context. So this is basically swap context because first time I call it, I call it get context and then do a set context and then whenever it comes back to me it just skips over. So this is, if you had to implement swap context yourself guess what, this is pretty much it which kind of mean if I just like don't show you this and say just do it. All right, any questions about that? Yeah, like when we're executing you threat, oh here? So it would switch the stack back over to thread A stack and it would resume executing here because this is the last place that UA called get context, right? So the I gets incremented to three whenever, so thread B would have incremented from one to two and then swap back over to A and then A would have not gone into here it would have went up to here and then I is two so it would have went into this while loop and then it would have incremented from two to three here and then print and then we would have got this print here and then it would have played with it then did another get context call which doesn't really change anything and then set context back to thread B which exits out of the while loop. All good, no questions? All right, cool, then we're done. All right, so just remember, pulling for you, we're on this together.


On Wednesday, October 18th, Big Sandy Community Action Program held a hiring event at the Pike County Library. Representatives from Pikeville Medical Center, Kentucky State Police, and other local businesses were in attendance to look for new employees. Some employers were also able to hire new workers on the spot. So basically we have 40 employers here. I think so far in the first 20 minutes we've had about 35 people show up. We shared it on Facebook and had about 1100 people share it. So we're hoping for a good turnout. We work in six sectors, healthcare, manufacturing, transportation, logistics. So we have PMC, ARH, an RS God one. We have some coal mining places, BNW resources, and then we also have teleworks. So we wanted to bring teleworks to give everybody an opportunity. So once you can't, transportation's an issue. So we wanted to give them an option to work from home. Appalachian Wireless is making it so easy and affordable to stay connected to friends, family, and the world. With the Forward Pay Unlimited or Unlimited Plus plan, get $50 off any Forward Pay device. And don't forget, with Forward Pay, there are no credit checks or long-term contracts. It's Forward Pay on the region's premier network, Appalachian Wireless.  We are Appalachian Wireless. Activation fee required. Just kind of apply that point of sale. The goal of the hiring event was to lower the unemployment rate in the area. Big Sandy Community Action Program is trying to make jobs more available for anyone seeking work. It's for unemployment and underemployment. So for people who are just having trouble making ends meet, come here, find a new job, try to increase your overall quality of life. Every employer generally leaves a two or three that they want to hire. We had double quick one year that had 14 they hired on spot. We identify a need and bring the job to the area. And it's five counties, Martin, MacArthur, Johnson, Floyd, Pike. So all of our employers work in those areas to keep it local. For Big Sandy Community Action, anybody who's not here today, if they need assistance with trainings or job search, they can visit one of our local career centers and we'll be more than happy to help. Reporting from Outant Top News, I'm Nick Collum.


Hello there, it's loud I'm Doug Shelley. I'm the vice president of product development at to Sora Today I wanted to talk to you a little bit about to Sora and our database the service platform So just a little bit of an overview on to Sora if you've never heard of us We are the trove company trove is a open-stack project I hope everybody kind of knows about the database the service project within open-stack We've been involved for about a year In the last cycle we were a top contributor to the project in Juneau to the trove project right now We have about ten developers in my group that are working on the project and we have a One person on trove core and he's sitting right there wave Amherst We have offices in Cambridge, Massachusetts and near Toronto, which is where I'm from So what we've built is a enterprise database the service platform that's based on trove It's it says the most advanced trove distribution available. I hazard to say it's probably the only trove distribution available The goal of this distribution one of the main goals is to provide enterprise support We're really looking to support enterprises as they roll out database the service particularly in private cloud and One of the things we're doing is we're basically and I'm going to talk more about this but we're basically providing a certification of the databases that are supported within the platform and The distributions that run open stack and I'll talk more about why that's important in a second We're we also really want to be the trusted advisor to the enterprise not not just merely Hawking software to them but talking to them about challenges with databases service particularly an open stack and You know advising them on how they can roll that out in a way that makes sense to them So One of the things we're going to talk about is what's unique about databases service So why is this different than other open stack projects? so if you attended This the session this morning by Jay pipes and Peter boros Which was all about my sequel running underneath open stack as the infrastructure database You start to get some appreciation why databases are different than some of the other pieces of the stack I think through their presentation. It's certainly elicited some of the complexities of of Managing my sequel in that environment. So so kind of we basically believe databases are different There's administration management each one of the databases, you know, like across my sequel Mongo Cassandra, they have their own personality Some of them weren't actually engineered for the cloud and that becomes material when you want to put it in a cloud And there's other systems that they rely on and not only your database is different in this context trove is a different kind of project So basically the trove project there's this concept of a guest agent Which is the proxy between the database and the rest of the open stack services Which is unique Which is kind of unique in the open stack ecosystem We want to provide consistent management across all the instances some of the other Neularities are the databases require tuning and customization and they're not it's not it's not the same across all of the database types So that tuning and customization for mongo is different than the tuning and customization for my sequel for example These guest agents can't be viewed like drivers You know drivers I think is a pretty common concept in the context of open stack these things aren't really a driver And the trove project it actually sits on top of all the other services and leverages novice in their swift Keystone glance so With our platform, we're actually trying to address these differences in a way that's meaningful to the enterprise So why would somebody want to use the to Sora database to service platform enterprise edition? So for three reasons it's robust. It's supported and it's interoperable. So by robust Not only are we help we're adding project adding features upstream that enterprises need so we're kind of driving Enterprise agenda within the within the open source project So we just recently added replication to the community. I'm going to do a demonstration of that in a minute The the enterprise edition is interoperable. So we're doing a lot of testing In our own environment testing across all the data stores and across all the distributions Which is something that isn't done in the community for this particular project and we're providing support So what enterprises expect which would be 7 by 24 SLA type level support? Okay, so here's a kind of your block diagram of what the offering is so starting at the The bottom left. I didn't realize I'm standing in front of the slide Sorry about that. So We start, you know, we talked about open stacks So everything's sitting on top of open stack on the bottom Then there's the trove database as a service open stack project right here. So we're basically wrapping that entirely In the first offering we have is our community edition So basically the community edition tracks the the stable releases of open stack, so We just released Community edition 1.2, which would be basically Juno trove Juno And we basically provide some extra things like the installation and configuration has been simplified Making it, you know easy obviously to install and configure for enterprises And we provide some extra management and it's and the community edition has it benefits from all the testing that we're doing as I've talked About and we will provide maintenance and bug fixes against the community edition as things are rolled into the stable branches On top of that is our enterprise edition So here what we're looking to do is over time at enterprise features And one of the things that we've done is actually accelerate some features into early release. So in Early September we released Version 1.1 of our enterprise edition it included some Juno features that we tested and accelerated into the release such as replication So people could have Enterprise access to that feature before it actually got released in in Juno, which was end of October We and then as I said the offering also includes the 7x24 support and SLAs Over time we're expecting to roll other features into enterprise edition that that could with that We would generally speaking upstream, but if the if the feature doesn't make sense to the community then it may not upstream It depends what it is. So we're evaluating those kinds of things Then on the right hand side another big part of our offering is These certified guest images. So as I mentioned the The trove Component is based one of the core things about it is there's a guest a guest agent and a guest agent gets rolled into an image and so when you Tell trove to provision an instance It basically spawns a nova instance and puts a guest image on it That's kind of pre-configured for for what you're provisioning. So for example If you say I want to my SQL database it would go pull the image that's associated with my SQL and Spark up nova against that. So This has been particularly challenging for people that have been trying to use trove over the time that we've been involved in the project Because the community provides tooling for creating these images, but you know It's just like a lot of the things people have trouble using the tooling and they're asking questions and then you know It's very challenging. So we decided to actually productize that So these images are tested certified by us and available for download as part of the platform So when you run the enterprise or community edition After you install it and it's configured You basically run this command and it'll pull whatever images you want off our site and install them into your Database to service component and we have images for All the databases that are currently supported. So like my SQL for Kona Mongoka, Sandra couch base Redis, I believe And as I said, we we were doing extensive testing on these images in the context of various distributions of OpenStack Okay, I want to talk a little bit about the Replication feature that we worked with the community to provide in the Juno release And specifically it was around read replica provisioning for my SQL So what did that include so in This is the first version of replication that was put into the trove project and we scoped it to include these Features so from a master my SQL instance that's been provisioned you can launch You can launch a replica. You can launch more than one replica The replica gets bootstrapped from a snapshot taken of the master at the time the provisioning occurs Currently it's based off my SQL native async replication and It uses the bin log position so it starts from a snapshot and then snapshot and then rolls forward based on the bin log position in my SQL master database as I said master can support many replicas and There's a concept of replica can be promoted or demoted so you could basically take a replica and make it the new master and knock the master So provides some the target of the feature was actually to provide read scale, but obviously if you have many slaves you could ultimately Promote one of them to be the new master at any point in time that you wanted to so Let's get into this demo Which If you've seen me do this before I like doing Video demos because they're significantly more predictable than relying on the vagaries of networking here So let's just go into this so One of the other things that we bundle with community and horizon community and enterprise edition of our product is a skin horizon that For the most part is is horizon over time. We've provided Various fixes to it that may that go upstream but may not be available in the open stack Say in in heist house. We put we pulled some things back from Juno and ice house for our versions Let's just fix some bugs in horizon. So So here we go. We'll sign in Okay, so here we go to the database panel Don't know if everybody's let me roll it up here, okay If you're not really familiar with trove, you would have never seen this panel probably if you don't have To sort debas or trove installed in your open stack. You'd you'd never get this Set of panels, but basically that pops up when you have a database service installed So in it has an instances panel. So one of the things you can do on the right side there you can launch and then the launch dialogue will come up here, so These are the things basically you provide when you want to provision a database in the so You name it You pick a flavor now one of the things you can do is you can actually establish flavors that are specific to Databases of service and the reason you'd want to do this is because different these different guest images and different databases may have different requirements from the other flavors that you have for Nova like they need more memory or more System disc or whatever So the other thing you can do I'll stop it there You can also provide a volume. So what that'll actually do is spin up a cinder volume and put the actual data directory for whatever the databases that you're provisioning onto that cinder volume You can imagine why that would be important Then you pick which data store inversion you want In other variations of this demo, we you know, there'd be more This will this would represent whatever listed data stores that you have installed and they all pop up and then you pick the version man The other thing you can do is You can have it create an initial database So in the context of my sequel it would that would be a database that shows up when you do like use database and You can create an administrative user. So we'll just go ahead and do that test DB test user password And I'm just gonna go ahead here click launch So now it shows up in here And it should launch relatively rapidly So what it's now active you can see that on the right I'm just gonna click on it Which is basically the show command and it's gonna list out this so this is my master and you can see all the way down here is the Basically the connection information. How do you get to it from whatever your application or client is? You can see that my user has been created and the database I made there the test DB Now what I'm gonna do is I'm going to I'm just gonna go into PHP admin kind of as like a canonical client And I'm gonna jam some data into the database so that I can actually prove that replication worked So I'm just gonna quickly Load some data a schema and data that I have created previously created So here we go customer demo schema I'll just go ahead and populate that and then query it So there we have some data Okay, so now I'm gonna flip back to to horizon here And I'm gonna I'm gonna launch another instance and it's gonna come up as a read replica So we'll just go through here quickly So name it pick flavor I'll pick the same flavor I used for the other one my sequel now Under this advanced tab now you have a choice you can restore from backup or you can now replicate from instance So I'm gonna pick my master So this is going to launch this instance as a slave or a read replica from that master So what is doing right now as you can see it's backing up the master and Then it's gonna send that backup over to so the backup gets streamed to Swift then it's gonna pull the backup off the Swift and Launch this new instance and restore that backup to it and then set up You know set up to my sequel replication Configure my sequel replication So here we are doing a show now on the slave. So a couple things here's its locator and then you can see down here It's now attached its slave of of that master And then master now shows that it has a slave And You can also see that and again this makes sense because it replicated it But it's it's now has the user and the database information that I put on a master and now I'm gonna go back into PHP my admin and I'm gonna connect to the slave which I've preconfigured with the address of that no instance and I'm gonna take a look at it and see if my data showed up there So there it is. Oh, and well, there's a schema. There's the data Now that's all well and good But the point actually the point of replication isn't to get the starting point It's actually be able to you know change data on the master as you go and have it show up on the slave So I'm just gonna prove that it got configured properly and that the data will make it across So I reconnect to my master and I'm gonna just go change a piece of data Here we go.  I think is what this table is for There we go. It's gonna change that to some number 5,000 and So now I've just updated my mat did an update SQL statement on my master I'm now going to just go over to my slave and Hopefully that change will have made it. What do you think do you think it made it? I Should make a version of the demo where that doesn't work then people would believe that it's real There we go 5,000, okay So what I'm doing here is I'm Forced my way under the instance. I'm gonna kill my sequel to show what happens if the master goes down so when the master goes down to chosen this detached state and the slave replication gets shut down on it because The rep that's kind of What happens when replication when my master goes away the replication stops now What I'm gonna do is start the master back up and you can see that this basically He'll come back to active and the replication will start again and the last thing I'm gonna Demonstrate is basically the detach operation so you can hit this detach command on the Slave and it basically will well It's hard to see it's turned off the replication which I'm gonna show but it stays as an instance It's now just independent of the master So if you go into the show you'll notice that the replica the slave of information is gone I think I think that's the demo. Oh, I'm gonna go into the master and show that the It doesn't have any slaves anymore Okay, oh It's starting again. Let me just go back here. Okay, so that was my demo Okay, so that's kind of the what I had today. We have a booth right over there, which is I 36 Please come and visit us lots of people there to answer any questions you have We have a cricketer artist who will draw a really nice cricketer over and give it to you And we have some swag. Everybody wants some swag. We have some swag. So So thank you for a question. I got one and a half minutes. Go ahead right, so Very good question. He's asking about what about high availability in the context of this feature So as I said, we scoped the initial my sequel replication kind of tightly so we could get it done And it was scoped to include only read replicas We are now scoping version 2 of that feature and it's gonna include failover features and that's being worked in fact There's a design summit session where we're gonna be talking about that on Thursday. So the intention is that'll be in kilo So we have 50 seconds anybody got another question Okay, as I said, feel free to come by and talk to us over the week. Thank you very much