Hi friends, welcome back to my channel and a very special welcome. If you're new here, my name is Jen. I'm a certified weight loss and nutrition coach. I follow weight watchers and I track calories and macros. Happy Saturday, it is Saturday, so it's grocery haul day. I have a fun haul for you from Walmart and a couple of really cool things I found at my local Target.  Subscribe if you're not because we do a grocery haul every Saturday and I upload five videos every single week. Down in the description box, I will link nutrition coaching where I offer personalized to you macros and calories. That is how I lost 90 pounds last year in almost 140 pounds total, as well as one-on-one coaching for accountability and if you'd like to chat with me directly. Links and discounts to my favorite things and don't forget, come join our Facebook group. We would love to have you. So let me flip you around and let's talk all about this week's groceries. So here is my grocery haul for the week. This week I went to Walmart. After that massive haul last week, I didn't need obviously that much, but there were quite a few things that I needed to pick up for the week. So the first thing I picked up was this Taylor Farm Sweet and Salty Snack Pack with a perfect bar. It was on sale for $1.79. Troy's gonna take this with him today. I thought that it would be just an easy quick snack. It's apples, pretzels, and then a mini perfect bar. Do you think the groceries are for you? You think it's for you? It's not for you, it's for daddy. Oh yeah, it's for daddy. Yeah, not Palmer, daddy. I was also super hungry, so I picked up, so I grabbed this little turkey pinwheel. I only ate half of them. It's just a tortilla with some turkey and cheese. It was pretty good. Actually, it was in the deli section. A few non-food things, paper plates. Can someone tell me when paper plates became astronomically expensive? This was $11 for these paper plates. That is crazy to me. And then we were completely out of foil and then Troy does the house cleaning and asks for a refill of the bathroom foaming bleach spray. I also grabbed some more of my favorite tuna packets. I'm obsessed with these. It makes such an easy lunch or snack, packed with protein. I really like the ranch. The lemon pepper is probably my favorite, and I'm not a spicy person, but I really wanted to try this sweet and spicy one. Another loaf of just regular white bread for Troy. Also, a refill of his favorite cereal. It's such a better deal at Walmart. I wanna say it was $5.79 for the big box, and I pay almost $5 for the tiny, teeny box at Kroger. So much better deal if you love Cauchy Cereal at Walmart than Kroger stores. I've also been on a major pretzel kick. I shared with you guys that I've been trying to decrease my fat. I'm always going way over my fat, so my fitness coach and I talked a little bit about that and how I can decrease that. And one of the things she recommended for a snack is pretzels, because it's carbs, which I'm always low on and no fat or very minimal fat. And I forgot how much I love these little itty bitty minis. I used to eat these all the time when I was only following Weight Watchers, so I'm really excited to have those again. The packet's a brown gravy. I am doing a crock pot recipe, like a chicken and gravy, not Felicia's recipe, but a different one that I found online. I also needed some feta cheese for a recipe, and this one was the least expensive option. More rice cakes. I'm down to two or three in the package. I eat these pretty much every day, whether it's with peanut butter on it, or sometimes I just eat a rice cake before I go to the gym for some fast acting carbs to make it through my workout. A gallon of 1% milk for Troy for his cereal. Can you guys hear Palmer? He thinks there's something for him. Hey, there's nothing for you. This is the grocery haul. This is the grocery haul. This is not for Palmer, Clayton. No, it's not for Palmer. It's a grocery haul for our friends to share with our friends. Hello, your brother. I needed some sun-dried tomatoes for my meal prep. I barely could find these. I finally found them by the canned tomatoes, which makes perfect sense. A couple of things of cheese, some light shredded cheese, and some light mozzarella cheese. These are for some dinner recipes. I finally found the Jell-O vanilla sugar-free pudding for my protein pudding, so I bought the big box. This, I can never find. It's always sold out. So whenever I find vanilla, I always buy the big, huge box of it. I did get some real bacon bits for salads, and I've been thinking this would be a good addition to add to an egg scramble to kind of bump up the protein. Two cans of the Healthy Request Cream of Chicken Soup. This is for that crock-pot chicken and gravy. Gross canola oil. This is for our Blackstone grill or barbecue. We actually have to oil it before we cook on it and after to clean it, and it makes sense to just use a cheap, crummy oil rather than my good avocado or olive oil. For produce, I didn't eat a whole lot. I just got an imperfect food box, but I did need spinach for my meal prep, and I scored on the price of this organic spinach. You already know our mini cucumbers. They are a little bit better deal at sprouts, but because I didn't eat a lot of produce, I skipped going to sprouts this week. A spaghetti squash for my lunch meal prep, a green bell pepper, and some Roma tomatoes also for this week's meal prep. I wanted to show you guys a couple other things. When Lola had chemo on Tuesday, I went to Target to get canned food and dog treats, and I saw these. You know how during Valentine's Day, Easter, they come out with the little mini packs of things, even Halloween? I found these lesser evil organic snack popcorns, corn and sugar cookie. Yes please, they are only 70 calories per little pack. I haven't opened them yet, but I'm so excited about them. Tori and I have been on a massive popcorn kick, and then, look what else I found. So excited about this too. I bought two. It is from the brand, Favorite Day, and it is Marshmallow Whipped Cream. Oh my gosh, I'm so excited. You guys know I've been doing the protein powder mixed in with non-fat Greek yogurt. I've been loving the Clean Simple Eats protein powder. If you missed Wednesdays when I eat in a day, I did a full review. I'll link Clean Simple Eats down below with a discount, but I've been loving their protein powder mixed with non-fat Greek yogurt with some whipped topping. So I was very, very excited to find that at Target. So that is everything that I picked up for the week from Walmart. Let's go ahead and jump into what's on my menu for dinners and what you'll see in Monday's meal prep. So I ran out of my other little meal planning pad that I bought from Walmart, or from Amazon, I don't know, a year and a half ago. So I found this really cute one on Amazon, super affordable. I think it was five or six dollars. I'll link it down below for you, but this is my new meal planner. So let's go over what is on my menu for dinners and meal prep. Today, Saturday, you know we always go out for dinner. Tomorrow, Sunday, I'm doing the crock-pot chicken and gravy. Monday, I am making Mexican pizza.  So stay tuned for that. Tuesday's leftovers. Wednesday, Troy asked for burgers. And then Thursday and Friday, we also do leftover night to finish up everything from earlier in the week. And here's what you'll see in Monday's meal prep. I'm super excited for my breakfast. I am doing another copycat recipe. This time, the Starbucks spinach and feta wrap. It is one of my favorite things from Starbucks. I'm so glad I found this recipe so I can make it at home because it's like five or six dollars at Starbucks. So I can't wait to make that. I'm also doing a meatball, spaghetti squash, kind of meal prep bowl for lunches. And then for dessert, I'm making protein cookie dough because I've been craving cookie dough and I'm gonna make it with protein. So stay tuned on Monday for all three recipes. Thank you for joining me for this week's grocery haul. I hope you enjoyed seeing all the good stuff I picked up at Walmart and those super fun food finds from Target. We have a super target in Tucson. I had no idea. It was like a dream. It was a huge target. And now I know I can go there when Lola has her chemo because it's about five minutes away. So that was fun to find those new things. If you enjoyed today's video, please give it a big thumbs up. It really helps out my channel. Subscribe, turn your bell on and don't forget to check out that description box. Nutrition coaching, links and discounts to my favorite things and my Facebook group. Come join us. We'd love to have you. Happy Saturday friends and I'll see you in tomorrow's video. Bye.


All righty, welcome back to operating system. So today we get to talk about locks, the solution to and the cause of all of our problems. So where we left off in lecture 17 is we had this code where we had eight threads incrementing a global variable 10,000 times. And we figured out that every time we did it, we got a different answer because they were essentially all fighting for it because the operations involved in this is a load, an increment, and then a store. So if we want to solve this problem, the first step to any solution is to identify and classify the problem. So our problem is something called a data race. And they occur when two or more threads are sharing some data. So a data race is specifically when two concurrent actions. So again, we don't need two threads. This can happen on a single CPU. All we need is concurrency, which we remember the difference between concurrency and parallelism. Yes, good. So if you have two concurrent actions accessing the same variable, and at least one of them is a write, you have a potential for a data race, which is you will get some unexpected results. So if two or more concurrent actions are just all reading a variable, that's fine. You have no worry of getting an invalid value or value that's about to change or anything like that because it doesn't change. So you have to have two concurrent actions, and at least one of them has to be a write. So next, we have to talk about what an atomic operation is. So atomic operations are indivisible. We tried to reuse the same word from chemistry, right? You have atoms, you can't go any lower than that. You can't break them up unless you get into your semiconductor physics courses and quantum mechanics and all the stuff I've since forgotten about. So an atomic extraction, it either happens or it doesn't. So you may assume it happens all at once. There's no sub steps that can be interrupted. It either happens or it doesn't. Can't preempt in the middle of it. There is no middle of it. It either happens or it doesn't happen. So you are only allowed to be preempted between two atomic instructions. So after instruction finish, then you can be preempted, switch to another thread, start executing something different, and then come back, but each one has atomic instructions that they execute. So if you want to get into some detail, so this will be a preview for a compiler course if you take one. So compilers just don't take your C code and then just do some magic and then give you some machine code. It will represent your C code in an intermediate language that's a bit simpler to argue about and more generic. So it's essentially kind of like assembly, but it's like generic assembly that doesn't matter what actual architecture you're using. So this is used for analysis by most compilers that do any type of optimization. So they change all of the C code you write into very simple statements that just do one thing at a time and you assume that each of these statements is atomic. So it's useful to represent your program like this because you can reason about data races and it's a bit easier to read than the actual assembly code. So all of the statements will have this form. So it will set something as a result. Well, it may or may not set something as a result, but this is as complicated as it gets. So it will set something and then do an operator on up to two operands and that's it. So for example, you couldn't represent one plus two plus three, you would have to break it off into several of these statements. So you would have to save the result of one plus two into some register or something and then add the value three to that. So this is what's used by compilers and then that's what they reason about and you assume each of these statements is atomic. So Jimple is the three address code used by GCC. If you really want to see what's going on, again, not required for this course, but in case you're interested, you can use this flag F dump tree Jimple. Don't ask me why they call it Jimple because they like naming things poorly. I think we all name things poorly. So I guess we can't really blame them. Look at what I called lab four. So here, if you want to see the tree, it's yeah, that dump tree Jimple. If you want to see all the three address code generated by GCC, you can use F dump tree all and you'll see just a bunch of compiler internal information. That will probably make no sense to you, but you can kind of read it if you've, well, you probably have read assembly before. So it's easier to reason about your code than low level assembly. Even if you don't know how to read it, it's actually pretty readable if you go ahead and dump it out. So if we do a look at the Jimple for that pthread data race, we kind of argued about before. So instead of count, we'll assume that, I mean, we're modifying a global variable. It's in memory somewhere. So we'll argue about it as a pointer to the count, which I'll call pcount. And that's just the global address. So the Jimple would be the following, which is kind of what I wrote out in lecture 17. So it's only allowed to assign one thing and then have up to two operations. In this case, the only thing it does here is a load. So this is a load into whatever. So that would represent a register for us internally in the compiler. It assumes you have an infinite amount of registers. So they just call them D1, D2, D3, that, that, that, and you can go up as high as you want inside the compiler. So this would be a load from memory. So I'm loading whatever the value is at that address. And then I am doing my increment. So this is my increment. So I get a new register value from the old register value plus one. And then I write out the result, whatever my increment result was. So assuming I have two threads executing once and initially that global variable is equal to zero, what are all the possible values of that global variable? So ideally, if the initial value is zero and we have two threads, well, one could increment it and then the other one could increment it so we could get two, right? Is it possible to get one? Yeah, it should be possible to get one because we have a data race in this case because they're essentially writing to that location as well. So we could have the case where one thread reads the value, we context switch over to the other thread, it reads the value which would be zero and then it does this thing we did in lecture 17 where at that point they would both increment the register and then write out the value. So in this case, to analyze data races more, you just have to assume all preemption possibilities to a single location. So if we call a read and a write from thread one like R1 and W1 and then we can call the read and the write from thread two, R2 and W2, we'll assume we can't reorder instructions within a thread. So you'll always see R1 followed by W1 and you'll always see R2 followed by W2. So you won't see W2 come before R2 or something like that. Although your compiler technically can reorder code and your CPU may reorder instructions too. So that makes your life even more difficult but we will assume no reordering in this course but in the real world, yes things might get reordered and it will really suck to debug those ones but for the most part, the compiler's do a good job. So if we are, oh yep. So in this case, we couldn't have a write one before a read one because we're accessing the same variable but if you have multiple values, variables you're changing, it could reorder the instructions if it wanted to. So if those were reads and writes to different variables, it could reorder between those and probably make your life a bit more difficult. Usually it's not a big deal. So in this case, if we argue about all possible reorderings, well the first thing that can happen is either thread one runs first or thread two runs first. So if we have thread one run first, well it would do the read and then after that, well we could have context switch back over to thread two and it could read and then at that point, the writes could be in any order and we would get one as our result for, in this order if we have, we don't context switch over to thread two, thread one would continue and then write, update that global variable and then we'd context switch to thread two and it would read it and then write it and our final result would be two. So any questions about that? Those are all of our possible orderings and you can tell how quickly this gets out of hand for a real problem. So this is just, this is two instructions, a thread and I'm only doing two threads. So you can imagine all the possible orderings that could happen if I have eight threads on the same value or if I have multiple values going or what have you. So arguing about this is going to be really, really hard if you have to argue about every single reordering. You want to be able to argue about your program such that you just don't have the situation for data races and we will explore that today. So our solution for preventing data races is essentially to prevent any concurrency. So there are something called a mutex and they are a type of lock and that's what we'll be talking about today. So you can create something called a mutex either statically or dynamically. So I could just create it as a global variable or something like that. And that is how I create a global variable. There's just this define that will go ahead and initialize a mutex for you. If you want to create them dynamically, you can create one using this pthreadmutex init and then you give it a pointer to whatever it wants to initialize just like the threads themselves. And then after you're done using it, you can call destroy on it. If you want to include attributes like the threads, you have to use the dynamic version. So this is the attributes pointer, but we'll just assume the default attributes. We won't need to do anything more complicated in this course, thankfully. So how do we use a lock? So with a mutex, you can do a lock call and then an unlock call. And this kind of works like a real life lock. So you can assume that this protected code, I don't know, is a bathroom or something like that. So assume this is a bathroom. So if you don't want multiple people in the bathroom at the same time, and just like you don't want multiple threads writing a variable at the same time. So you can think of it that way. A little bit ridiculous, but hey, go with me. So this lock call is essentially the same thing as you have a key, like there's only one key.  So that means that if any other thread tries to do this lock, you have locked yourself in the bathroom with the key so they can't get in. You're the only one that can execute this code at any given time.  So any code you have before or after, you could have another thread switched to, you could have concurrency all over the place, but between the lock and the unlock, you might get context switched out, but because another thread cannot get this lock, it cannot execute this code. So even if it executes, it could execute this concurrently and then whenever it hits unlock, if your thread has the key, it can't get past this function call. So it has to wait for you to unlock before it can proceed. So we called this code here, this protected code a critical section and that means only one thread can execute it at a given time. So with this, this prevents a data race because now we only have, if we have our update to a variable here, we only have one thread there at a time. So therefore we don't have any data races even if it writes to that variable because we got rid of that condition where we have two or more threads concurrently accessing a variable. So the problem of this is, well, we have a new situation called deadlocks, which we'll get into later if we have multiple mutexes, but for now let's just assume a single mutex and there's also this pthread try or pthread mutex try lock that will essentially try and get the lock and then tell you whether or not it succeeded. This lock call will block, so it will wait until it can proceed and it gets the key. So let us see how we use it. So if we want to fix our data race code, well, all we're going to do is create a mutex that we are going to use and then in the run, all we do is our data race goes between just the counter variable. So we had multiple threads reading and writing to that variable. That's what plus plus counter does. So we can do a lock right before it and then that means only one thread at a time can be executing this increment and then after we're done the increment, we unlock it. So if, whoops. So if we compile that, we get 80,000 every single time. So if we got rid of the data race, everything works properly. So any questions about that? Yeah. So if I lock and then another thread tries to call lock, so that's what's actually happening right now. So if another thread tries to call lock, while another thread has a lock, it will just block there and wait until it can actually acquire the lock. So it'll just be stuck in a queue. Yeah. So a mutex is just, it's a name for a lock that just ensures, so mutex is short for mutual exclusion. So it's just something that will ensure that only one thread is there executing that, whatever is between lock and unlock at a time. Yeah. So you might need multiple locks if say I had another variable I was incrementing. Well, I could reuse the same lock, but then I don't really need, if I reuse the same lock, everyone's fighting over that key when really I could make them two separate ones. So typically with locks, I essentially make this part serial. So you want to make it as small as possible for performance and make sure that threads aren't constantly fighting over it. So in this case, this would be real bad for performance because I'm essentially making every thread, like I'm essentially doing this line in serial and all the other threads are just fighting over the mutex over and over again, because only one can execute this at any given time. So one increments it, seven are waiting, trying to fight over the lock, then whenever that one's done, one of the seven gets it, probably goes and recues and it's lots of fun. All right. Any other questions about that? So this is like using mutexes will be the bane of our existence because we can screw them up real nice. So. Something went wrong. Please try again. Yes, something did go wrong. We use mutexes. All right. So here is all we did to prevent a mute or to prevent the data race here. So we just created a mutex at the top, did a lock and unlock call. So we turned any code between the lock and unlock, essentially serial. So only one thread can execute that at any given time, preventing data races. So we won't have the case where that number the counter isn't 80,000, but we probably just made things a lot slower. So again, that code between lock and unlock is called a critical section. And again, that means only one thread execute that a given time. So those critical sections, while they need to be safe, so they have to ensure mutual exclusion, which again means only one thread should be executing that critical section at a given time. Also with the lock, we should have liveness aka progress. So if multiple threads reached that lock call or that critical section, one and only one must proceed at a given time. And that critical section shouldn't depend on any outside threads at all. You can mess this up and deadlock and that means other, a deadlock just means no threads can make progress. Your program just kind of sits there and halts and it can't do anything. We also should have kind of like scheduling. We should have bounded waiting, aka it should be starvation free, which means if a thread makes it to the lock call, it should eventually proceed. So it shouldn't just get stuck there forever, just like in scheduling. Well, if a thread want, or if a process or a thread wants to execute, it should execute at some time in the future. It shouldn't just go in limbo forever. So if we want to implement it, well, we want them to have the least overhead as possible. So we want them to be efficient. We don't want to consume resources while a thread is waiting for another thread to finish its critical section. You want the locks to be fair. So you want each thread to wait approximately the same amount of time. And they should be simple so that your locks should be easy to use and hard to misuse. And similar to libraries, you want like layers of synchronization in your program. So like your hardware will have low level atomic operations that either happen or they don't. We'll get into some of what they are to build these locking primitives on top of. But for now, we don't need to know them. So on top of the atomic operations supported by your hardware, you have the high level synchronization primitives. So that's where like mutexes would live. And then building on mutexes, you have your properly synchronized application and a properly synchronized application has no data races. So it behaves the same way every time doesn't have data races and doesn't screw up essentially. So if you want to use a lock to implement a critical section, if you have a system with only one processor on it and the only source of concurrency was interrupts, this is a implementation of a mutex lock. So your lock function could just disable interrupts. So if you disable interrupts, that means you don't have concurrency anymore if that's your only source of concurrency. So then after the lock, nothing can interrupt me. I'm the only thing that can execute. And then my unlock could just be to re-enable interrupts. So the idea behind that as well, if I disable concurrency, I'm all good. But this isn't going to work if you have multiple cores. Also it's not going to work for your application because no operating system is actually going to let you disable interrupts like hardware interrupts. So clearly this was a good idea, but it's not going to work on a real system. So let's try to implement it ourselves in software. So here's a lock. We'll just represent the lock as just a int. So we're going to use the value of zero in a nit. So zero will mean that no thread has a lock. It is unlocked or that door is unlocked. And we are going to use one to signify that, oh, some thread has locked it. So in the lock function, I'll just have this while loop. So it has a semicolon here, which means if that condition is true, it will just keep on iterating over and over again, like it won't exit the while. It will just check the condition over and over and over again. So while the value of this lock is one, which should mean that some other thread has the lock, I'll just keep on retrying it over and over again, just reading it over and over again because I want to wait for that lock to become zero, which means some other thread unlocked it. So if the value is zero, I will change it to one to signify that I have locked it. So if I pass lock, that means I'm the only one with it and I should be the only one allowed to continue here. To unlock, we just change the value to zero to signify while we're done with it. So is this going to work? Is it, with this implementation, is it always the case that only one thread can call lock and only one thread proceeds? Yeah, so his thought is, hey, if multiple threads call lock, there is a situation in which all of them will pass it and all of them will continue, which would mean I implemented a very crappy lock. So anyone want to explain why that is the case specifically or what? So does everyone see why that's possible that it could happen? Yeah, isn't that just an edge case? But we have to argue about all the edge cases here because we're trying to implement a lock, right? So if initially, so this is our lock code, let's say two threads call lock. If two thread call lock, it should be the case that every single time only one of the two threads can make it pass the lock call at a given time, right? That's the idea of our lock. So if initially the value of the lock is zero and we have thread one and thread two, ideally how this should work is, well, thread one will read the value of L. In this case, it would be zero and then it should break out of the while loop and then set the value to, set the value of L to one and then that way if thread two calls lock at this point, well, it would read the value of L, it would be one and then it would just keep on retrying over and over again until eventually thread one, it switches back to thread one and then thread one calls unlock which just does a right to L of zero and then eventually this one would, we'd switch back to thread two, it would read the value of zero and then it would break out of the while and then go ahead and write. So in that case, only one thread makes it pass lock at a given time, right? So is there a situation where this is not true where they both make progress through it? And remember this is data racist so we have to argue about any concurrency switches that could happen, so is there a bad time to switch between the threads that will cause us to behave unexpectedly? Yeah, yeah, so if we context switch right after thread one reads, well, then we context switch over to thread two, it would also read the value zero and then at this point both of these would just write the value one to it and both could make it through, oops, and then both could make it through the lock call which means we're screwed. So two threads made it through, two threads would be executing that critical section, it could concurrently switch between them, you can't argue about that, so this is a very poor lock. So any questions about that? Being a bad idea and of course this could happen even if we have eight threads, all eight threads could just read the value of zero, context switch read zero, context switch read zero, da, da, da, and they could all make it if we got super unlucky. And that unlucky is like, you have to argue about every case once we deal with concurrency, so you have to prevent all this. So we can all see that this implementation is bad, right? No arguments about that, this does not work because multiple threads can call lock and make it through before another one even calls unlock. All right, so other issues, yeah, it's not safe, so if we have two threads, there is a possible way for both of them to be in a critical section and it's also not very efficient, so the other thread that doesn't have the lock, it's stuck in that infinite while loop as long as before the other one calls unlock. So why is it just reading the variable over and over and over and over again when we know it's not going to change until the other thread calls unlock? So there's no point in just letting it execute. So that is what is called a busy wait because it's just waiting, it's just essentially burning CPU cycles on something you know that will not change. So any questions about that at all? All right, so I left some additional time. If we want to go and talk about Lab Four, oh, Lab Four's fun. Oh, how would we fix that problem? Yeah, so we'll go into more of it tomorrow or not tomorrow, next lecture. So that, so yeah, all we're up to today is that crappy lock. As long as we know it doesn't work, it's good enough. We'll figure out how to fix it later. So, hey, all right, I assume people have like not read this yet. Oh geez, all right. So you are implementing your own user threads. So you will implement essentially like the interface will look exactly like P threads a little bit. But they're all going to be implemented not as kernel threads.  Like when I showed you how to use you context to essentially create a thread. So in this, I added a new session called progression. So all the test cases are ordered. So you can actually pass the first test case with writing like two lines of code. So I suggest you do that. So you, so like for example, this is how the test cases work. So the test case essentially runs this test function and this test function is run in a new process so it can figure out, you know, if your process terminate or if you terminated early or what happened with it. So this will just run in a new process and it will use your library. So you write a knit function, you can do whatever you need to in it. And then it will just have a sequence of other calls that should hopefully work. So as part of this, if you initialize a library, well, you should represent the current main running thread as thread zero. So in this case, this what ID should return the ID of the current running thread. So the current running thread, this should return zero. All the test cases use shared memory. So you write a value to shared memory and then the test infrastructure will go ahead and read it as soon as your process is done. So you should only write to one of these shared memory locations or the test will only write to one of these shared memory locations once and that's it and it will check all the values in this check function. So if you get any errors, they will look like this. This string will be printed. So if your ID returns negative one or something like that, well, this function is going to check that the integer at that memory location is zero. If it's not zero, it'll give you that message that says the main thread is wrong. And this is like the include for your library and this is the include for the test infrastructure that you don't really have to worry about. So the only things you have to know about the test infrastructure is that there is a test function that runs until it completes and then this check function that runs afterwards that checks all the values. So any questions about that are all right. So let's try and explain a more complicated test case and we'll kind of explain what each function does. So as part of this, so you can initialize your library then you can get the ID of the main thread and then this is how you create a new thread. So p thread create, essentially it needs to initialize some structure or something, all the structures will live in your library and the only argument you give what create is what function to run whenever that thread executes. So in this case, I'm going to create a thread that will run t one run and then create another thread that runs t two run. If you read the description of what create, it will say that, okay, you should create IDs with the low like create IDs sequentially with the lowest available number first. So if the main thread is thread zero, this thread should be called thread one, get ID one, this thread should get ID two. So you can see that here that that's where the return values go and the test case, it says, oh, okay. The ID of the second thread should be one. The ID of the third thread should be two. So that's how you read them. So in this one, how it will work is you maintain essentially a ready queue of all the tasks of what create will just create a new thread, set it up to run using make context, all that fun stuff we showed earlier. And then you would also have a queue that represents your waiting or ready threads, which I showed you how to use a queue. So your library should have a queue, thread zero should still be running after the create calls and our ready queue should be one and two. And in this case, we're just executing in FIFO order. So if we do something like join, join will do what pthread join does. So it means thread zero is going to wait for thread two to finish. So that means thread zero cannot execute anymore. It essentially blocks. So thread zero will block and because thread one is at the front of the ready queue, that would be the next thread that starts executing because of this join call. So thread one should start running and it should start running this t1 run function. So since, so there's this fun function also that we have called whatCancel. So whatCancel is essentially like a kill-9 for threads. So whatCancel, that means that the thread specified by that number is now automatically terminated. So this gets into like, how does this interact with join? So if thread one cancels thread zero, it means again, thread zero is now terminated, it is dead and nothing is attempting to join on thread two anymore because what thread one was doing when it got mercifully killed is it was joining on thread two. So now because it got killed, nothing is waiting on thread two anymore. So what we do here is, well, we join on thread zero which is terminated at this point. So what join should do is immediately return not switch to any different thread or do anything crazy like that should just immediately return and what it returns is the status of that thread. So the status is pretty easy. If the thread gets canceled, its status is 128. If it just terminates normally using exit, status should be zero. So in this case, we write out the result of join. It should be 128. And then here thread, the next step is thread one joins on thread two. So that means thread one can no longer execute because it's waiting for thread two to terminate and we need to figure out something else to run. So at this point, our ready queue would only have thread two in it and that's the only thread I can now execute. So we would start executing thread two and there's nothing else in the ready queue because thread one is now blocked. So whoever wrote this test made a global variable called x up here and because it's a global, well, it'll be affected by everything. So thread two increments it. It reads the value of it to make sure that we incremented it from zero to one and then we create a new thread which should get the ID of zero because that is now the lowest available ID because thread zero has been joined. So the new thread should get ID one. It's set up to execute this null run which doesn't do anything, it just returns. And then after that, we write the value we get to make sure that it's value is zero and then at this point, thread two run is done so you should need to implement implicit exit so that's not done for you like in pthreads you're implementing the thread so you have to do it. So there's like essentially two ways to set this up. You can use UC link and make sure it goes to some other thread you control that does some cleanup or you can essentially use an argument to pass an integer to that run function and then you can figure out what function you need to actually execute in there and then make sure it ends with a exit or what exit. So in this case, if thread two implicitly exits thread one should now unblock and get added to the ready queue. So the ready queue should now be thread zero which is the one we created to run that null run function and since thread two is done, we should just execute whatever is next on our queue which is thread zero. So we start executing thread zero starts executing immediately exits so it exits and the only other thread to run is thread one right now which should resume from this point. So it should return from this join and give you the status of whatever of thread two. So thread two exited normally so it should get a status of zero. Then to make sure we are executing thread one it will increment that global variable so it should go from one to two, then we read it then thread one should exit here and then the process terminates because it's the last thread that can execute. So any questions about that? This is like a hard test case. Yep, so T two run. So it just increments this global variable and then it creates a new thread that executes this null run which doesn't do anything. Yeah, so as part of what create returns the ID of the newly created thread and it's always supposed to be the lowest available number. So in this case because yeah and you can only reuse a number after another thread joins on it and then you can release all of its resources and everything like that. So if we didn't join on thread zero then that number wouldn't be available and we probably would have created thread three or something like that. So yeah, we created thread zero because let's see, at what point? Yeah, so we went here T one, we canceled it and then we joined it. So because we joined it, that means we can, our library can reuse ID one because ID one doesn't represent a thread that exists anymore. So now we essentially freed up ID zero. If we do what create, we get ID zero because it's now available. If we didn't join, we essentially would have like a zombie thread, right? So it keeps its ID until something else joins on it. So we could still join on that same ID if we want. So if we create a new thread, we'd get ID three. All right, any questions with their walkthrough? Yeah, you should use UC link to like have something clean up at the end and call what exit or you should just set up your make contact such that it calls a function that will run whatever the requested function is and then do a what exit at the end. So there's no one way to implement it. It's like one of the only like tricky things to do in this lab. But other than that, it's just maintain a queue. All right, so any other questions? We've seen the code. So make sure that's the beginning. You have an early testing. So just has a main function. You write whatever you want, write the checks and you will get the results. So if you have any questions about the behavior for what happens if you cancel or join a canceled thread or you join a thread before it gets canceled or any weird interactions that you think is an edge case, go ahead and throw that in the test. All you have to do is call check to check any return value and then I will run the solution on your code or on, yeah, on your code you submit and you will know the result and know what the solution should do. So other than that, read the functions. Hopefully the description is clear. So if it is not, let me know. And with that, just remember, phone for you.


Okay. Good morning and welcome. Let's begin with the word of prayer. I want to request any of us to please lead in prayer. So feel free. Am I audible? Yes, ma'am. Am I audible? Okay, sure. Okay, let's pray. Our great family, Father V, thank you for this beautiful day and beautiful morning, Father God. You include your presence, Father God, towards us. Father God, this time, we just to praise you, just to worship you, Father God. We choose to give thanks to you, Father God, for all of us, Father God, for all our lives, Lord. As we are going to, this time, as we are going to learn your word, Father God, from Book of Acts, Lord. We pray that, Lord, just the Holy Spirit will lead us and guide us, Father God, so that we will learn the deeper things, Father God. And we will go deep and take, Father God, in your truth, Father God, and we will pursue more of you, Father God. We will know you in a more, in a more way, Father God. And we ask you, Lord Jesus, Father God, you move around us, Father God.  Please submit, Father, to your mighty hand, Father God. Let's use her in a mighty way, Father God, so that whatever the world will come, it will come through the Holy Spirit. Thank you, Jesus.  And we ask this prayer in Jesus' mighty name. Amen. Amen. Thank you, Abinash. As we are aware, we've been, you know, looking at the Book of Acts and covered up to Acts 7. So today we are going to do Acts 8. We'll do it slightly differently.  And then I will kind of, you know, share from it. Not that I'm going to summarize it and make it very short. But wherever the emphasis required, scriptures in those places, there'll also be an emphasis. The easy part about Acts 8, 9 and maybe even 10 is it's more like it's already, you know, been narrated like a story by Luke. But more so in these passages, we can see different events unfolding. And so it's easier to follow. So I again require volunteers. It's a rather long passage, Acts 8. So maybe one of us can read, you know, Acts 8 and verse 1 to 20. And the next person can read from verse 21 all the way to verse 40. A little slowly so the class can understand what is going on. So, yes. Now Saul was sent into his death. At that time, a great persecution arose against the church, which was at Jerusalem, and they were all scattered throughout the region of Julia and Samaria, except the apostles. And the divine man carried Stephen to his burial and made great lamentation over him. As Saul saw, he made havoc of the church and drained every house and dragging off men and women, committing them to prison. Therefore, those who were scaring them everywhere, preaching the word, then Philip went down to the city of Samaria and preached Christ to them. And the multitudes with one accord heeded the things spoken by Philip, hearing and seeing miracles which he did. Some Korean spirits crying with love came out of many who were possessed, and many who were paralyzed and lame were healed. And there was a great joy in that city. But there was a certain man called Simon who previously practiced sorcery in the city and astonished the people of Samaria, claiming that he was someone great, to whom they all gave his place to the greatest, saying, this man is a great power of God. And they heeded him because he had astonished them with his sorceries for a long time. But when they believed Philip, as he preached the good, as he preached the things concerning the kingdom of God and the name of Jesus Christ, both men and women were baptized. And since Simon himself also believed and when he was baptized he continued with Philip and was amazed seeing the miracles and signs which were done. Now when the apostles who were Jerusalem heard us, Samaria had received the word of God. They sent Peter and John to them, who when they had come, then prayed for them that they might receive the Holy Spirit. For as yet he had fallen upon none of them. They had only been baptized in the name of the Lord Jesus. Then they laid hands on them and they received the Holy Spirit. And when Simon saw that she was delaying on one of the apostles, hence the Holy Spirit was given. He offered them men saying, give me this power also that anyone on whom I already have may receive the Holy Spirit. But Peter said to him, your money perished with you because you thought the gift of God could be precious with money. Thank you Asha. We would require another volunteer to read from verse 21 till verse 40. Can I go? Yes please Charles. I'm using another version. You have no part or share in this ministry because your heart is not right before God. Repent of this wickedness and pray to the Lord in the hope that he may forgive you for having such a thought in your heart. For I see that you are full of bitterness and captive to sin. Then Simon answered, pray to the Lord for me so that nothing you have said may happen to me. After they had father programmed the word of the Lord and disfied about Jesus, Peter and John returned to Jerusalem preaching the gospel in many Samaritan villages. Now an angel of the Lord said to Phil, go forth to the Lord, the desert Lord that goes down from Jerusalem to Gaza. So he started out. Then his way, he made an Ethiopian innock, an important official in charge of all the treasury of the Kandake, which means queen of the Ethiopians. This man had gone to Jerusalem to worship. And on his way home was sitting in his chariot, reading the book of Isaiah the prophet. The spirit told Philip to go to that chariot and stay near it. Then Philip returned to the chariot and heard the man reading Isaiah the prophet. You understand what you are reading? Philip asked, how can I? He said, unless someone explains it to me. So he invited Philip to come up and sit with him. This is the passage of the scripture the innock was reading. He was a little like a ship to the slaughter and as a lamb before its share is silent. So he did not open his mouth. In his humiliation, he was deprived of justice. Who can speak of his descendants? For his life was taken from the earth. The innock asked Philip, tell me please, who is the prophet talking about himself or someone else? Then Philip began with that very passage of scripture and told him the good news about Jesus as they tripled. Along the road they came to some water and the innock said, look, here is what the heart can stand in the way of my being baptized and he gave orders to stop the chariot. Then Philip and the innock went down and put the water and Philip baptized him. When they came up out of the water, the spirit of the road suddenly took Philip away and the innock did not see him again but went on his way releasing. Philip, however, appeared at Azotus and traveled about preaching the gospel in all the towns until he reached Caesarea. Amen. Amen. Thank you Charles for reading the remaining portion of Acts 8. So we will get started as we have already seen the events continue from the death of Stephen. So we saw earlier on in Acts 6 that there was a selection of seven volunteers to serve the church in their time of need. The challenge which the apostles had was the distribution of food to the Greek speaking widows and so they picked people who not just had the skill to meet the need but they were also people with spiritual capacity so we saw that they were filled with the Holy Spirit. There was a good report and these were people of wisdom and so eight of these people were chosen and the situation was taken care of. And later on, while the church is growing, something else that we are noticing is that the opposition against the people of God is going to the next level. Earlier the apostles, we saw from the healing of the lame man at the gate, beautiful, we saw that there was opposition after opposition against the apostles. Earlier it was Peter and John and later it was all the apostles who were questioned but God had his own way. Initially they were threatened and they were left. The second time there was a word from a learned man called Gamaliel and that was well received by the council. And so they decided that if this is a work of God then nobody can stop it and which is how the apostles were actually let go. And we saw that from that time onwards the persecution is becoming sort of stronger against the believers. Stephen, he was questioned, he was accused wrongly and he gave a defense for himself and we saw the wisdom of God upon a man like Stephen that even the people who were questioning him, they couldn't say anything and which is why they got frustrated.  So that's where we stop. Now after the death of Stephen there seems to be the mention of a man called Saul who apparently was leading the killing of Stephen. So here again in Acts 8 verse 1 it says, Saul was consenting to his death. So it shows us that this man Saul, we've seen that he was part of that entire team that questioned Stephen but also that whatever Saul did he did it very willingly. So he was consenting to the death of Stephen. It wasn't a forced thing so it just goes to show us how zealous Saul was for the things that he believed in. So obviously he believed that Stephen and the people of his congregation were against the Jewish God and the Jewish traditions and that's why Saul was very angry and you can see that even in the rest of this verse 1 till verse 3 you can see that because we are told that this man Saul was consenting to the death and he was part of a great persecution that arose against the church. Now when persecution arose we might think that the work of God will stop but see the mercy of God and the goodness of God even in tough times scripture tell us that from Jerusalem what happened persecution started people probably fled that place to save themselves but they ended up being scattered throughout the regions of Judea and Samaria. So the apostles stayed back in Jerusalem but the believers spread across the regions of Judea and Samaria and therefore what can we expect we will see as we go forward that these believers took the gospel with them. So the gospel was not limited to Jerusalem but it spread across the entire region. So we thank God that persecution in itself is not the end of the gospel. All this happened 2000 years ago and here we are today. We are all people of different nations, different tribes, different tongues continuing to speak the truth of Jesus talking about the redeeming work of the cross because no persecution that has ever risen against the body of Christ has been able to put a cap on the gospel the way Jesus commissioned the believers and said go into all the world and preach the gospel even up until today the gospel is being shared. And as Gamaliel said if this is the work of God nobody can stop it. So even persecution could not stop the work of God. People would have thought the council and the authorities would have thought that they can threaten the believers and that will stop their enthusiasm but it was not a human enthusiasm but it was really the work of the Holy Spirit in the lives of the believers that they got scattered but that resulted in the blessing of the church anyhow. So even persecution in a way led to the spreading of the gospel and thereby a blessing to the kingdom of God. So now believers are in Judea, they are in Samaria, there are open doors in new places to talk about Jesus and then later again we continue to read it says devout men carried Stephen to his burial. So there were some Jews who probably understood what Stephen was sharing. So not all Jews were against Stephen or maybe even the believers but there were some who were against, there were devout Jews who helped in the burial and they were quite sad about the death of Stephen. Once again there's a mention of Saul and it says he made havoc of the church. So the zeal of Saul, you see again the zeal of Saul against the church of the Lord Jesus Christ and Paul later on makes mention of the zeal of his in Philippians 3, I think it's verse 6 and by nature, by personality seems to be somebody who's passionate no matter what is on his plate. So earlier he was a passionate persecutor and later he was a passionate apostle of the gospel of Jesus Christ. How passionate was he in the persecution? It says dragging of men and women committing them to prison. So generally even when it comes to punishing those who believe contrary to the authorities, they would have some compassion on women but you notice Luke writes dragging of men and women. That tells us that Saul was brutal in his persecution. He believed fully in what he was doing. He didn't care what gender you are, who you are, maybe even the age but it shows us that he was a very convicted persecutor. It also says house to house, entering every house, entering every house. So then you see how passionate he was about dealing with those who believed in this Jesus. So that's a little bit about Saul and later we have the introduction of Philip as a minister of God. Earlier also the name of Philip is mentioned in Acts chapter 6. There we see him as one of those volunteers.  No wonder he was chosen to serve in the distribution of food. But after that there's a little bit more that we learn about the volunteers. We learnt about Stephen, what a testimony. He is just a volunteer. Nothing more is mentioned in the Bible about Stephen. Similarly at this point Philip is a volunteer. So what is Philip doing? We will read about that. Verse 4. Now again it says those who were scattered went everywhere preaching the word. See the flip side of persecution. It caused people to go everywhere. Wherever they went they preached the gospel and Philip chose to go down to the city of Samaria. And what did he do? He preached Christ to them. So notice how preaching Christ or sharing the truth of Jesus was so integral to every believer. Earlier it says those who were scattered. So our assumption is there must have been hundreds, thousands of believers who probably got scattered. But it was just part of their lifestyle. Wherever they went they preached the word. And similarly Philip being one of those believers he went to Samaria. He preached Christ to them. And scripture tells us multitudes with one accord he did the things spoken by Philip. So people in Samaria heard the word of God. What else happened? They also saw miracles it says. So hearing and seeing the miracles which he did. So Philip began to, I wouldn't say began the ministry in Samaria. Other people may have gone ahead of him and done some ministry work. But there was some prominent work which Philip did in Samaria. Now what is the importance of this place called Samaria? Samaria was known as a lower community of mixed race Jews. Because apparently the Assyrians had taken over and they had intermarried. So the Samarians were no longer respected by the pure Jews. So even at the time when we read about the Lord Jesus walking past Samaria and meeting the woman at the well in Samaria. There was an inhibition that Jews generally had towards the Samaritans. So this was the inhibition that they were not a pure breed so to speak. Among the Jews there were all these classes and ways of honoring or dishonoring groups of people. So the Samaritans were a group which was not well respected. But see here what did Jesus say? In Acts 1.8 you shall receive power and the Holy Spirit has come upon you. You shall be my witnesses in Jerusalem, Judea, Samaria and to the ends of the earth. So you notice that God promised for the Gospel to touch the ends of the earth. God promised that beyond the Jews the Gentiles would hear the Gospel, others would hear the Gospel. And it's beginning to happen, it's actually beginning to happen. This was not an easy thing before the Lord Jesus' death and his burial and resurrection. But after the death, burial and resurrection of the Lord Jesus we see that the covenant was opened up to the non-Jews as well. So it's a very beautiful thing that ministry is being done in Samaria. Samaria which was a so-called rejected community of people as far as the Jews were concerned. But for God there's no rejected community. All are created in his image and God loved the people of Samaria. So no wonder people when they were preaching Christ to them and Philip went in and did some prominent ministry. So what was part of his ministry? Just like Jesus, remember earlier in Acts 1 he said Jesus began to preach, teach and he also performed his healing ministry. So there was a preaching and a demonstration of the work of God. So that was the proper kind of ministry which Jesus did and the apostles followed in the same method of doing ministry. So what is Philip doing here? Philip preached Christ to them and then it says what the multitudes he did him, hearing and seeing the miracles which he did. So Philip is preaching but Philip is also demonstrating the kingdom of God and then we read on verse 7. Unclean spirits crying with a loud voice came out of many who were possessed and many who were paralyzed and lame were healed and there was great joy in that city. So notice how the ministry is so similar to the kind of ministry that Jesus was doing. Preaching, demonstrating, part of demonstrating healing, deliverance. Philip's ministry is very very similar and people are experiencing what is being done by the power of God. And notice verse 8 over there, very beautiful verse it says and there was great joy in that city. So how does the gospel impact cities of the world? How should it impact cities of the world? When the gospel comes firstly the truth of God's word reaches us, reaches our every part of our being that now we are redeemed because of the work that Jesus has done for us. We are saved, we have salvation in Christ Jesus and not only that the release of God's power there must have been people who were sick and bound by sicknesses. There must have been people who were oppressed because of the works of demonic powers but here is Philip coming and preaching the truth. So the truth has hit them and not just that the power of God has hit the city. So what is the result of that? There was great joy in that city. So whenever we think of missions, whenever we think of preaching the gospel somewhere, remember this. As Philip ministered in the region of Samaria there was great joy in that city. So our ministry brings about great joy when we preach Christ and we demonstrate the works of the kingdom of God. So as these things are happening we will see the response of an individual as well. And scriptures point out that there was a man by the name of Simon. So what is so special about this Simon? We are told in verse 9, he practiced sorcery in the city and how well did he practice sorcery? He was not just any sorcerer, scripture also tells us astonish the people of Samaria claiming that he was someone great. And here is Simon who is probably one of those ace sorcerers doing his black magic, witchcraft, depending on the demonic powers for his supernatural works. So he is doing it at a great level and his impact seems to be really great because we are told he astonished the people. So demonstrations of the supernatural through the life of Simon, it was incredible. To what extent was it great? Verse 10 we are told that they all gave heed from the least to the greatest saying, this man is the great power of God. This happens isn't it? So when people see supernatural power in and through somebody's life, they don't just honor that person.  In this case they have named him the great power of God. Man is the great power of God. So in Samaria, Simon is an influential, if you want to say, you know, religious or spiritual, spiritual, individual. Now what happens to Simon? But when they believed Philip as he preached verse 12, so Simon is doing all these wonderful things. But Philip comes and he preaches and when Philip preaches, okay, and scripture also says that both men and women were baptized. So his ministry was quite effective. People heard him and they came to faith in Jesus and that is why men and women were baptized. So Philip is doing good ministry. Verse 13, then Simon himself also believed. Now think about this.  Of course, you know, we know that.  Okay. And what else do we see? Simon was baptized and he continued with Philip. That goes to say that Simon was born again. The sorcerer was born again. The sorcerer also wanted to become a disciple, which is why he continued with Philip and notice the last part of verse 13. What did we say about Simon? He was so well-versed in the supernatural that he was called as the man, the great power of God. But last part of verse 13 says, Simon was amazed seeing the miracles and signs which were done. So something for us to learn here. You know, many times we look at supernatural demonstrations and some of them we know are in the name of Jesus. Some of them we know are from the kingdom of God. But we also look at the supernatural demonstrations which come from the kingdom of Satan and, you know, the demonic world. And we say, look, even Satan is able to do miracles, even Satan is able to do the supernatural. But there is something greater about the supernatural which is released from the kingdom of God. Why am I saying it? From Simon's story, from Simon's, you know, the way Simon reacted to what he observed, he was already great in the supernatural. But after he becomes a believer, he sees Philip moving in miracles and he was amazed seeing the miracles and signs which were done.  Yes, the demonic world can demonstrate a little bit here and there, but that's about it. You know, it can never compare to the supernatural power of the Almighty God. So that is something, you know, we must recognize. And this is nothing new because even when we see the example of Moses, do you recall? He went back to the palace of Pharaoh and the sorcerers competed with him. But in the end, what happened? The snake which came out of the rod of Moses, it ate up all the other snakes of the sorcerers. Just to show that the power of God is way greater than anything that the demonic world can produce. So here is a sorcerer who is touched by the gospel. Okay, so from now on, we'll also begin to see different kinds of people.  So people of different strata of society responding to the gospel and how the gospel is not limited to only one class of people. Right, we already saw that it's gone to the Samaritans. So that is a big deal in itself. Okay, and also various kinds of people being touched by the gospel. So in this case, Simon, an influential spiritual man becomes a believer. He himself is amazed by the supernatural that Philip demonstrates. Okay, now move on verse 14, what happens? Now Simon, we said, is he a believer? Definitely because he believed so clearly Luke wrote and then what does he say? He was baptized. Okay, and he follows Philip wherever he's going. So he's growing in the things of God. Now what happens to Simon and his faith? That is what we are going to read. Just before that, we see in verse 14 that when Peter and John or the apostles in Jerusalem heard about the ministry of Philip, they sent Peter and John. So the apostles heard and they sent Peter and John. So again, you see this as a pattern in the book of Acts, you know, wherever there are believers, it's great. It's wonderful, but something more needs to be done. Remember in the Great Commission, we've been asked to make disciples of all nations. So even as a young believer for me, the only thing that I used to want is to see people saved. So I'll be very happy when I hear, oh, so and so has accepted Christ. So and so is now a believer. They are now saved. And that seems to be the end of what we expect of people. But in the Bible, just when people get saved, the apostles seem to look at it as the beginning. It was never the end. So when we go somewhere and there is an evangelistic work which is done, evangelistic ministry takes place. That's not the end. It's the beginning. So here is Philip in Samaria. The report would have gone to the apostles in Jerusalem that people in Samaria have accepted Christ.  And what did they do? Did they just sit back and relax and stay on in Jerusalem? No, they realized that they have more work to do. So the apostles now sent Peter and John, two more apostles so that these new believers in Samaria can now be discipled. So you will see throughout the book of Acts that as much as evangelism is important, discipleship is also equally important. We will also see the deliberate effort of church planting. So this is technically the beginning of the church in Samaria. So generally, they would just call the church of a region. So church planting is taking place. So where do we get all these principles that we practice today? It's coming from the practices of the early church, the early believers. So as soon as they heard that in a given region there are believers, that was the beginning of the journey of the church of Samaria. So what did the apostles do? Come on, Peter and John, get ready, take your bus flight, whatever, go there. Verse 15, they came down, Peter and John, they came down to do what? It says, they had come down, prayed for them that they might receive the Holy Spirit. So do you see a pattern here? Very much because every time somebody accepted Jesus Christ, they would be led into water baptism. We saw that earlier also, whenever Peter preached, water baptism was a common thing. And we are going to see from now onwards that Holy Spirit baptism, though before this it's not mentioned in a very specific manner, it's understood because when you read about Stephen, a man who was mighty, performing mighty signs and wonders, and Philip who was also moving in the supernatural, it's understood that they were also baptized in the Holy Spirit. So this is a pattern in the early church that you become a believer, be baptized in water, be filled with the Holy Spirit. So why did Peter and John come all the way from Jerusalem to Samaria so that the Samaritan believers may be baptized in the Holy Spirit? So verse 15, who when they had come down, prayed for them that they might receive the Holy Spirit for as yet he had fallen upon none of them. They had only been baptized in the name of the Lord Jesus. So verse 17, how do they minister the baptism in the Holy Spirit? So here we see, then they laid hands on them and they received the Holy Spirit. So sometimes today, we practice this when we are praying for people for the baptism in the Holy Spirit. We lay hands on them. Why are you laying hands on them? Because we see this done in the Book of Acts. Now do we always have to lay hands on people for them to receive the baptism in the Holy Spirit? Not necessarily because in Acts 10 we will see that Cornelius and his household were baptized without the laying of hands. But there is a common practice which we observe which is laying of hands. So Peter and John came, they prayed for these new believers, laid hands on them and they received the baptism in the Holy Spirit. So this is all happening in Samaria now. What else do we see? So Simon is observing what is being done by the Apostles verse 18. And when Simon saw that through the laying on of the Apostles hands, the Holy Spirit was given, he offered them money. Saying, give me this power also that anyone on whom I lay hands may receive the Holy Spirit. So Simon as he is watching all this, one inference that we can come to is there was something supernatural about the baptism in the Holy Spirit. So maybe when people were baptized in the Holy Spirit, one we know earlier they spoke in tongues. So probably they would have spoken in tongues which Simon viewed as something supernatural that could have been healings, that could have been deliverances. You know something has happened that impressed Simon. Now we know about Simon's background. He was into sorcery. So he has seen the supernatural from the negative side. But if Simon is impressed by the baptism of the Holy Spirit to the point that he's saying, I need this. Even if I have to give money, you please give it to me. It shows us that there was something supernatural that took place at the time when Peter and John were ministering the baptism of the Holy Spirit to the people. If this was not so, why would Simon say, I will give you money? I want this power. Definitely he saw something supernatural. That is why he's desperate to get that power. And he says in verse 19, give me this power also that anyone on whom I lay hands may receive the Holy Spirit. So what Simon asked, we might think, wow, this man desires the Holy Spirit. Isn't that good? We might think that, yeah, that's so good. But again, by the discerning of spirits, you could say earlier in Acts 5, when Ananias and Sapphira, they sinned in their hearts against the Lord through a word of knowledge Peter knew. And he said, why have you lied to the Holy Spirit? Similarly, Peter in the Spirit recognizes that Simon's motivation is not correct. He's asking for the Holy Spirit to be able to give it to others, which even we desire. Normal believers, we must desire that. But the motivation, the attitude with which Simon desired the Holy Spirit was so wrong. So in verse 20, Peter said to him, your money perish with you because you thought that the gift of God could be purchased with money. You have neither part nor portion in this matter, for your heart is not right in the sight of God. So you see, as scriptures tell us, God sees the deeper things. Man sees the outside, but God sees the heart. So for us as believers, our inner attitudes, the way our heart is, when our heart is good ground, when our heart is aligned and is obedient to God, God is pleased about that. But when we step out of that zone, God knows. And that's what happened in this case. Simon did not carry the right heart before God. He was trying to buy, what did Peter say? You want to buy the gift of God? How can you buy the gift of God? Is that the reverence that you have placed on the gift of God? So he rebukes him and he even sort of, it's almost like a curse. Yes, he says that, gift of God purchased with money, you have neither part nor portion in this matter, for your heart is not right in the sight of God. Earlier he said, your money perish with you. So very strong words coming from Peter. But Peter also adds in verse 22, it's God's grace and mercy somehow towards Simon, where Peter says, repent therefore of this, of your wickedness and pray God if perhaps the thought of your heart may be forgiven you. So God offered Simon forgiveness. And Peter is able to discern the spirit and the heart of Simon. So in verse 23 he says, for I see that you are poisoned with bitterness and bound by iniquity. So there was something spiritually wrong with the attitude that Simon carried. How is this possible? How can a believer, how can a believer, a disciple, a follower of the Lord Jesus be poisoned by bitterness and bound by iniquity? But scripture tells us that we must not open the doors to Satan. We have to shut the doors on Satan. But when we open the doors to Satan through our wrong patterns of thinking, through sin in our lives, through the works of the flesh. We are entertaining Satan. When we do things like this, what happens? Satan can come in. And we can be distracted, worse still. We can be derailed from the path that God has for us. So it's a warning. It's a warning. Simon is a believer. He definitely is a believer. But his attitude is not correct. He's not humble and submissive before the Lord. He's not obedient to the Lord. He has become poisoned by bitterness. So why did he ask for the gift of God and try to purchase it with money? Maybe competition, jealousy, envy. They have it, I wanted. I can become a big man. Or maybe you could even say that he did not fully deal with the pride of his past life. He was considered the power of God among the people. But maybe he was missing the feeling that being called the power of God meant to him. And now nothing. Once he started following Jesus, he has none of that. But suddenly when he sees the supernatural being demonstrated through Peter and John, he becomes hungry. He becomes covetous. His pride kicks in. And he says, even if it takes money, I'm going to buy this so that when I lay hands on people, that these kind of supernatural things will take place. And so Peter rebukes him. Peter also calls him to repentance. And he speaks forth what he sees in the spirit about Simon verse 24. Thank God Simon responded positively. Then Simon answered and said, pray to the Lord for me that none of the things which you have spoken may come upon me. So he humbled himself, Simon humbled himself. And he prayed, he pleaded and said, please, whatever you have said, let it never happen to me. And in this, we see that Simon probably went ahead and walked the path of repentance. Now what actually happened to Simon? Because it's not recorded in the book of Luke or elsewhere in the epistles. It's very hard to say. There are people, you know, extra biblical accounts where people say, yes, Simon repented and he was a faithful believer of the Lord Jesus throughout. And then there are extra biblical reports that say that no, he didn't fully repent. He carried on with his pride and, you know, he wasn't a strong believer up until the end. So we don't know. These are all speculations. So we don't know what happened to Simon. But he had a good response. Please verse 24. He says, pray to the Lord for me that none of the things which you have spoken may come upon me. So he recognizes the authority, you know, of God, the kingdom of God and the apostles of God, you know, at this point. So verse 25. So when they had testified and preached the word of the Lord, they returned to Jerusalem, preaching the gospel in many villages of the Samaritan. So mission strip is over. Okay, so basically they've taken the journey back to Jerusalem. These apostles that intention was Samaritans be baptized in the Holy Spirit. So they came, they did that. They went back to Jerusalem. But how did the mission strip come to an end along the way, preaching the gospel in many villages of the Samaritans. So they did not limit themselves only to the place where Philip preached. But everywhere they went, come on, let's make it a, you know, a missions program, preach next, preach. And that's how they carried on. Okay, so let's pause here. We'll come back and we will pick up from verse 26. Okay, so thank you everyone. 10 minute break for now.


Welcome back to Watchin' Baseball, a series in which Jake and myself watch baseball. Baseball! No touching on this show. So we've been just shaking hands using my mannequin's hand. I was going to turn around and have you shake it, which was like we're shaking hands. But now we've kind of just shook hands.  Well, OK. And we shake. What words are we in here? We are in the 1984 World Series between the San Diego Padres and the Detroit Tigers. This was labeled by Sun as the fast food World Series because Ray Kroc McDonald's owned the San Diego Padres. While I think it was the Pizza Hut guy owned the Detroit Tigers. We're going to jump in a game five. None of these games fit our exact billing. Time out. Time out. Time's out. Time's out. 30 seconds. So a Pizza Hut guy owned the Detroit Tigers. And then the Little Caesars guy owned the Detroit Red Wings. At one point where two major sports franchises in Detroit owned by fast food pizza. Yes, I think the Little Caesars thing is more recent, but yes. I think it was like 93. This is 80. Around there. 84. So. All right. Well, we don't know a lot of these guys. We are not experts. We are just the fans of baseball and we watch it. Yes. Unfortunately, we have to do that disclaimer every time.  Oh, my God, what's this? It's a shirt from our store. Go check it out when you get a chance shop dot johnboymedia.com. Whoa. Oh, my God. Another one. Yeah, it's floating around like fireflies business. Jake, it's it's a one run game. Tigers are up by one run. The Tigers can clinch. Yes, they win three games to one. Something I read was that both of these managers were the same managers from the 1972 World Series, but they're on two different teams, but their personal vendetta. They were sleeping with each other's wives and stuff. It got messy. All right, here we go. I think Reds and A's managers. Oh, smokes. Reds and Asia. OK. Goose. Goose is up. Goose, Gossage versus Marty Castillo. Have a nice day, Marty Castillo. Yeah, he's a guy. I looked at his baseball reference. Don't feel bad about not knowing him. Goose hits him down right quick. I'm going to keep talking fast the entire video. Here we go. I think also kind of important in this game, both starters got yanked early. Mark Thurman for the Padres went 0.1 innings. Thurman the worm. Thurman the worm, Mark Thurman the worm. And then Dan Petrie Dish only went 3.2. So we're we're into the bullpen. I am so excited that we have a real baseball field. Felt like it's been a while. Look at that grass. Yeah. You like those Padres jerseys? I was just going to ask you, I'm I don't I picture them earlier in time. I picture them as like 70s Padres mid early 80s. I appreciate the color scheme. Like I like that the Padres brought Brown back for now a day like right now. Sitting them down. This is coming in, baby. But for something I don't like about her Gibson. He is finally involved. Goss was too busy trying to intimidate a nobody. Moose. I mean, now I kind of like him. Great day facial hair. Yeah. Lou versus Goose. Lou Whittaker. Sweet Lou Whittaker. That was his nickname. It was actually sour Lou. Safe. Good call. Is that Steve Garvey? Yeah, he's in every game I walk. Yeah. To Garvey just went World Series team to World Series team. I've watched more Steve Garvey than any baseball. Goss Corona. But yep. I don't know if you had no idea.  Oh, almost got him. Reminds him that he's still there. That's just Goose saying, I know you're there. Padres with a couple guys from different teams. I wonder if Ray Kroc. Oh. Ooh. Oh. Well, OK, I'm going to pause it real quick. Nettles was a little Cavalier about the whole thing. I mean, yeah, that's who he is. It's Coxman. He's a good player. Who do you think this is on Nettles for not having any urgency? Templeton. I think the throw gets there, right? Oh.  No, he's good. It's not the strongest throw. He's just not standing on the base. What are you doing? Hello. Might have been safe anyways. Yeah, I think it was. I think it was. I mean, it's a real Halloween finish. That's a great call. Was this played on Halloween? No. A real Halloween finish. It's just a great line. Ooh, interesting. I think he might have been safe anyway. So I don't know if you can do error, but either way.  Yeah, it's just one of those things. Dick Williams. I like this broadcast. So this is a very famous moment. October 14th. Goose shaking his head. No, let's go after him. Yeah. So have you ever seen the video with the audio? Video with the audience. There's this clip out there. Yeah, you can hear Goose talking. So Goose says, let's go after him. And the manager says, what do you mean? Like, strike him out? And Goose goes, yeah. Oh, yeah. And then the Detroit manager says Sparky. Sparky. You'll see, he starts mocking them. Like, they're scared of you. They're not going to pitch to you. And I started saying this before, but all my big Padre fans reach out because, I mean, there's a lot of dudes from other teams on this Padre team. Gossage, Nettles, Garvey at first base. Like, did Ray Kroc go out and buy some guys? What was happening? I need to find the clip where they're mic'd up for you. OK. It's reach out, reach out to Jake. All you Padre fans, hostile bunch. That smile is so good. Use these. That's coaching. Look how happy he is. It's a great smile. All-time smile hall of fame, Sparky Anderson. That needed to be part of it. So, you know, infield in. No, I'm going to go after him. What do you mean, you're going to strike him out? Nettles said he's going to play halfway. Yeah. We got that. You don't tell me what to do. I do what I do. Thanks, bud. Oh. Oh.  Smoked it, upper deck. Loads the game open, 5-4 to 8-4. Yo, I love this stadium. Yeah. I've never seen this view of it. I think this is old. Camarica? What's the name of this ballpark? Dude, upper deck dead center? Yeah, because isn't this the stadium that? It's illegal now. Cecil Fielder almost left or something, and that's a famous swing. I don't know. Yeah, this is in Detroit, Tiger Stadium. I know that is the original. I think they filmed the movie 61 here, but all right. Pardon me for the people that are getting upset that I don't know this, but no batter's eye, which they can't do now. But I've never seen upper deck center field. I don't think. I'm trying to picture upper deck center field. I'm feeling like Roger Center has some out there. Indoor stadiums have it, but that doesn't count. OK. This is cool. Legal. Hey, guys. Giving the crowd a little bit, yeah. OK, giving the crowd a lot of it. OK, soaking it up. Good for him. Wonder if he. So the high-fives here. The high-fives been invented. Yeah. This is huge. Wonder if he ever gets another chance at the World Series. Oh, I'm going to cut it. Do you want to see if that other video had a mic'd up version of it? Sure. Got a voicemail. Did you hear that laugh? Yeah. The Tigers wrapped up the series. Oh my god, that is incredible. Sparky. Don't walk him. Don't walk him. Hey, Roger. They didn't want to walk him. His smile, man. I'm all about that. His smile beforehand. The top one smile I've never seen. Knowing it's going to use these. OK, coach. Will do. Goose. Well, to be fair, he knew he was going to get him in the air. He didn't want to bring the infielding. That boy. Gibson giving out a little bit of the cop from Stranger Things vibes. Yeah, he's also, look, he's still going on. They didn't want to walk him. Inverted. I don't know who this is. What a moment. Doesn't matter. Basically won the World Series. That smile from Sparky is great. It's great. All time. I mean, he knew it right away. Yep. Put him up, put him down, Goose. And again, this goes. That's it. You're right. Who's announcing this World Series? I'm digging this guy. He let that whole thing breathe. That's one of your favorite things for the announcers. Vin Scully. That's what I thought. I thought it was Vin Scully. But I was so scared to take a guess and be wrong. Don't let the people get to you. Because you want to know why I knew it was Vin Scully? Because it's the same guy for the love of the game. And I watched that as like a 10-year-old or whatever. And that's when I hear Vin Scully's, I think of Kevin Costner throwing a perfect game. I was scared to guess. Not guess, but say that. Ow. Saying ow when the catcher gets hit. In the mid-sentence. Feisty people of Detroit. So when did Tiger Stadium end? Maybe 2000s? No. No. Well, I didn't see the seventh inning. I got picked off the inning before. Should we jump to the silly? 2009. They demolished it in 2007. Or 2009. But they were trying to demolish it for a while. Raging Bowers filmed there in 61. I knew 61. They used this as Yankee Stadium in 61. It was the same style. You want to skip to the celebration? I think so, yeah. Game's over. Just spoke. That's what he looks like without that hat. Strike. Ooh, I like that pitch. It's a little low. Too bad. It's a little low, but I liked it. Yeah, they started off this year 35 and 5. Pretty good. They won by 12 games. That's what I read. Pretty good. Turns on it. Still keeping the goodbye check on. What up here? Number two? Not cheater. Outside. You're wondering who this is for the pirate? Screwball needs to come back, right? It's just a change-up. Like what Tommy Cainley throws, they would call it a screwball. Lance Parrish. See those cops celebrating while sitting down? Who's this pump? One out of way. Look at him. So excited. Oh, wow. I forgot about the locker room ties. What do you think he's going to host it? This might be a familiar face coming up for baseball fans. That was Alan Wiggins. Now we have a 23-year-old. Tony. San Diego State. Win. That guy doesn't look like a baseball player right now. He's a pitcher without his hat on, Jake. That's tough. He throws the hat on. My god. That looks like your older cousin. Yeah. There he is. Is this Tony? Tony looks good. Yeah. Doesn't want that. Never has. Tony's got to put it in play, right? I'm loving the look of this. I think it's because the last three or whatever years it's all been shitty, astroturf fields. Fly ball to left. That's a nice way to win. You made that call the other day. The fly ball last out is so much better than the strike that last out, because you get that breath. Yeah. And bam. Let it build a little bit. We still got some fans on the field. Yeah, I mean Detroit. You're not stopping them. So what's this to do?  Yeah, but is he trying to just celebrate with Gibby?  He should be so happy right now on the field as teammates. I think he went for like a dapp up. Chaos. That is a cool stadium, though. That guy just got. You're right with the full wrap around in center field does add an effect. And that's when you hear old broadcasters talking about or old players being like, yeah, I couldn't see anything in the batter's eye. Yeah. Because it was people. Stealing grass. Who do you think's in the locker room? Oh, we don't know. Nobody. We'll never know. Just a team. Well, congrats. Congrats to the Tigers. When is the next World Series? Have they won in one sense? Have they won one sense? I don't know. No idea. They didn't win one with the Verlander price team. So unless this team got another one, which is possible. Anything's possible. Anything's possible. That was refreshing. That was aesthetically, I'm talking about. And Vin Scully obviously was amazing. Vin stood out. Yeah, stood out. Really good, which is. Adds up. Adds up. The field was beautiful. Uniforms were all right. I appreciate what the Padres are doing. Yeah, I think of those Padres unis a little earlier in time. Like 1940s. Too far back. They probably didn't exist then. Far back. They didn't exist then. That's the end. Watching baseball. Thanks guys. We'll be back on Monday. No Sunday. No Sunday episodes watching baseball. We will be back. Oh, this is Monday, Seth. It's Monday. Hey. Hiya, bye. See you guys later.