Hey guys, Coach Mack here with this week's Beneath the Surface powered by Microsoft Surface beginning now. Today we're going to look at the run game from both the Titans and the Texans. Texans are in 21 personnel. The Titans are in a five man front with a too high look in the back end. Jeffery Simmons is on the three technique on the right side. He just forklifts the left guard into Pierce the running back and essentially makes the tackle with Kenyan Green's backside. No physical domination in the run game. This was to continue all day for the Titans against the running attack of the Houston Texans. The Titans are in 12 personnel, three by one initially. Texans are in an eight man front as they were the entire afternoon trying to stop Derek Henry. Number two Woods goes in motion. Number 85 Chig comes across in a nice crunch block, excellent block back by Jones on the shade. Davis nice combo up to the second level. Henry has an excellent vision. On the rollback makes number 32 miss classic stiff arm on number 36 and is caught initially in the secondary by Nelson for a 41 yard game. 11 personnel, Titan number 81 Hooper goes in motion to form two by two. Henry offset to running backs right side, inside zone handoff. Read option look holds the defensive end. Malik Willis makes the proper read as a quarterback off of number 97, gives it to Henry. Excellent blocks by Brewer, Petit Ferrer on the second level linebacker. Henry runs through the arm tackle of number 97, makes a tremendous Okie doke move on the safety and then excellent blocks downfield by Conley and Westbrook, a keen aide and then classic Derek Henry, stiff arm and one of the better touchdown runs you're going to see by Derek Henry for six points. Titans on a four man front with two high safeties outside zone to the closed side. Rich, Bud Newprey and Kevin Strong build a solid wall on the front side and Big Jeff now playing a shade technique, completely destroys the down block by number 64, gets four and a half yards deep in the backfield, running back tries to reverse field, bad bad decision. David Long cleans it up for a seven yard loss, again Titans were dominating on defense against the run game all afternoon. This TD is number 75 for Derek Henry setting a Oilers Titans record, passing Eddie George for the all time TD record. Number 75 is in Dylan Radins as an extra tied in on goal line offense, Texans are in all up defensive front on the goal line. Swing goes in motion, this is total domination by the entire Titans offensive front for this record setting touchdown, look and see Toro in the end zone in the space suit saying Houston we have a problem.


Thank you to the Brain Foundation and donors for the gifts we're receiving tonight. MRIs are rapidly evolving field and it takes a while for some of the developments in that area to make their way to clinical practice. And part of the research we're looking at is translating some of those techniques to the area of childhood stroke. Childhood strokes are one of the leading causes of death and disability in children and about half the survivors suffer some sort of long-term physical disability or intellectual disability. A common example of physical disability is weakness or paralysis on one side of the body. We are going to be interested in finding out how the brain rewires and repairs itself after stroke and why some children recover better than others. We're going to be looking at two groups of children to investigate this difference. The first group is those who recover well from childhood stroke and the second group are those who don't. We're going to be using two types of MRI to look at these children. The first one type will be looking at the grey matter in the brain. The second type will be looking at the white matter. So functional magnetic resonance imaging or fMRI is very sensitive to the differences in oxygenation of the blood in the brain and therefore tells us in which areas of the brain the neurons are firing. And we expect to see differences in activation patterns between the two groups of children we're looking at. The second class of MRI is diffusion imaging and that lets us look at the white matter structures in the brain. The white matter contains the brain's wiring that connects the transmits electrical signals between the different parts of the brain and the rest of the body and we're expecting to see differences in how the two groups of children recover. What we're hoping to find is markers, imaging based markers that let us determine which children are likely to recover well and therefore guide rehabilitation and treatment of these children. Thank you.


Okay, apparently we're still figuring out where classes are, that's not good. All right, so today we are going to further talk about threads and their implementation. So this should help you understand Lab 2. Quiz one, I still don't know what it looks like. So in a lot of ways, we're ahead of the other class, so we're at least two lectures ahead of them minus some other stuff. So if you look at on Ashwin slides, there's some questions at the end, that will probably look like the short answer part of it. I look through them, we can answer pretty much all of them, I think, except for anything that has to do with an MMU. We don't have to know that because that's how you actually implement virtual memory and we'll see the entire implementation when we talk about virtual memory. Yeah, the rest is multiple choice or true, false, probably be conceptual stuff like system call stuff, threads processes, what's an address space, stuff like that. Yeah, some threads stuff will be on, but not like super implementation detail. So you should know because what we're going to talk about today, we pretty much already talked about with processes like context switching and all that, so we'll see. So all that stuff you should know. Yeah, it's online, so how am I going to stop you? It's open internet. I'm sure the TAs aren't going to watch you or do anything, so I don't know how on earth you would stop someone. So let's talk about threads implementation. So there's a few multi-threading models that you can take when you're implementing threads, and the question pretty much lies in where do we implement threads? We can either implement them in user space or kernel space. So what you'll be implementing in lab two are user threads.  The kernel doesn't know about them, hence their name user space threads. So the kernel doesn't treat your process any differently according to the kernel. You have a single process that has a single thread, and what you do with that single thread is completely up to you. So if you want to put threads on top of it, which is what you'll be doing in lab two, you are free to do that. But kernel threads on the other hand are implemented completely in kernel space, so the kernel actually knows about them. So the kernel manages everything for you, so it allocates the stack for the threads, which is what you'll be doing in lab two, and we'll take care of all the context switching for you because essentially it can just reuse all the process context scheduling because it's the same thing, except it has to do even less. So it just has to swap the registers, which would also swap the stack, and that's it. It doesn't have to change the address space or anything like that, because we all know now that threads are in the same address space as the process. So yep, yeah, and all the registers. So it's pretty much the registers, which one of the registers is a stack pointer, so every thread needs its own independent stack, so it can go ahead and execute normal C code and be independent from each other for only executing code. Other than that, right, it shares shared memory so they can see the entire heap. So no matter where threads are implemented, there's going to be a thread table somewhere, so it's similar to a process table, except it is less information because a process table will contain all the registers and stack, which is what a thread is. It's just like a subset of a process because the process also has the address space information, all the memory, the open files, everything kind of related to a running process. So this could be in user space or kernel space, depending on where your threads actually, where your thread support actually lives. So for you, it will be in user space, but there are kernel threads in the Linux kernel, so there are some section of that dedicated to storing information about threads. So unfortunately for you, for user threads, there also needs to be some type of runtime system to determine scheduling. Thankfully for you, at least in lab two, it's going to be quite easy because you're just going to have a queue of threads that want to run and they're going to request to run and then you just serve them in order. But yeah, so a process table is just all the information associated with a process. So it's just a big structure. So yeah, it was in one slide that pointed where in the kernel tree it was. It's like that, it's called a task struct, so it contains all the information about a running process. So it has all the registers, it has scheduling information, or memory information, open files, and that's where the process control block. Yes, the process control block? To a certain degree, okay. The process table is just a bunch of process control blocks. So that's how you keep track of all the running processes on your machine. Okay, so if you have user threads, you have to determine your own scheduling because you can't rely on the kernel, it will schedule your process, but you have to determine which of your user threads runs at any particular instance. But in both models, threads live within a process. So you could avoid system calls, that's one of the benefit of doing user level threads, or which especially was a benefit back in the day when you only had a single CPU anyways. So you can't avoid system calls because it's actually quite slow to transition from user space to kernel space, have the kernel do some stuff and then transition back from kernel space to user space. So for pure user level threads, you don't have to do any system calls. So they're gonna be very fast to create and destroy and there's no context switches that happen within the kernel. You of course have to do your own context switching, which again is lab two. But the drawback of this is that according to the kernel, you process only has one thread. So if your current running thread, if your current running like user level thread hits a system call, your entire process is going to be put to sleep while the kernel goes ahead and resolves that system call. So any of your other threads aren't going to be able to run. So by having user level threads, you will not have any parallelism whatsoever, right? Because it only will execute a single thread. So you can do things concurrently with just a single kernel level thread, but you can't do anything in parallel without the kernel's support. So for kernel level threads, they're going to be slower because creation involves a system call. But if one thread blocks, the kernel actually knows about them and knows they are all independent streams of execution. So if one of your thread blocks or is doing a system call, then another thread can be scheduled to run while it's waiting for that one. So, and again, if you have eight cores on your machine, for example, and you have eight threads, it can go ahead and schedule them all in parallel because it knows about them. But all threading libraries will at least have some user code. So the pthread library that we saw before, that has some aspect of library code that we'll kind of see what it does and we'll see through the magic of strace what system call ptrace actually uses, or sorry, pthread. So the thread library is going to map user level threads to kernel level threads, and then there's different ways of kind of breaking this down. So what you'll have in lab two is called many to one. So many user level threads are going to map to one kernel thread, which means your library completely exists in user space. So again, as far as the kernel is concerned, you have one running process, which of course just has one thread. In the one to one model, one user level thread corresponds to one kernel level thread. So that means the kernel handles everything, it does the context switching for you, it does the scheduling for you, but of course you're at the mercy of the kernel as to when your thread actually runs. And then there's many to many, which is kind of weird and is something they did in the past, it's not really used now, it's a bit complicated, and we'll see kind of a better way to do that. But many to many just means that many user threads can be mapped to many kernel threads, it's not exactly a one to one correspondence, and it's not exactly a many to one correspondence, it's somewhere in between. So the main to one is a pure user space implementation. Again, this is just lab two, so there will be no system calls, you will be managing everything yourself. So it's going to be fast, and it's going to be portable because it is purely written in something like C, which is basically just portable assembly, and you're not depending on any system calls, so you can reuse it on Windows, you can reuse it on Mac, Linux, doesn't matter, it's a pure C implementation of threads. And it's just a library, but drawback is again, that if one thread blocks, then the entire process is going to block, and another thread can't make any progress. So it can't do anything in parallel because again, the kernel only sees a single process. So back in the day, this may have been good when we only had a single core on our machine, but everyone probably has at least four cores on their machine, so this probably isn't a good thing to do anymore, although you still get to implement it. So one to one just uses a kernel thread implementation. So there's just a thin wrapper around the system calls, just to make it easier to use. We'll see that the system call is kind of weird looking, and it still has to allocate some stack space. So the kind of P thread implementation is going to malloc a thread for the new kernel thread, and then essentially tell the kernel where that address is, and then the kernel takes care of all the scheduling and the context switching, and which would be swapping the registers and everything like that. So this is the way to exploit the full parallelism of your machine, because the kernel has full knowledge of everything, and it can schedule all the threads to run as it wants. But again, this has a slower system call interface, and in very, very niche scenarios, you might want to control the scheduling yourself. If you have threads that maybe have higher priority, or you know one always needs to happen before another one, so you essentially give up that freedom of writing your own scheduler by just using the kernel scheduler, but thankfully for all of us, the kernel developers are quite smart, and the scheduler is quite good. And this is the actual implementation typically people will use, and for Linux with P threads, this is the actual implementation. So the many to many is a hybrid approach. So the idea is that, well, I might want a lot of user level threads, and more of them than kernel level threads. So if I only want to ensure that I have parallelism, and I don't and say each thread is really, really expensive to create, well, then I'll just create the number of kernel threads equal to the most parallelism I can get out of my machine. So if I only have eight cores, I'll create eight kernel threads, and then I can put like 10,000 user level threads on top of that, since they'll be cheap. So the idea is to kind of get the best of both worlds there. So you want to get the most out of multiple CPUs, and also reduce the number of system calls. But however, this kind of leads to a more complicated threading library, and then depending on your mapping luck, you may block other threads by accident, since again, the kernel doesn't know about them. So you still have that same issue. So if you map, you know, if you have tons and tons of user level threads, and you map a hundred of them onto a single thread, and they happen to all contain blocking system calls, well, the kernel can't schedule between those, because again, it can only schedule what it knows about. And it makes things very, very complicated, and we'll see just a technique that kind of uses this idea, but it's a lot easier to implement. But the threads get to complicate the kernel and make our life difficult. So the question is how should fork work if I have a process with multiple threads in it, right? It's kind of weird if it's an exact copy, should it be like an exact copy and copy all of the threads? That would get out of hand very, very quickly, and also make a fork bomb with threads, very, very effective. But so the way the Linux kernel deals with this is that whenever fork happens, it will create a new process like fork does, and that process will only contain a single thread and that will be the thread that called fork. So that way you avoid some potential issues of if you fork, right, it's just a snapshot at that point of time, and if there's multiple threads running, they might be playing with memory and like kind of halfway in between some operations. So after the fork and you have two processes that are now independent and then one only has a single thread, it might be in some weird undefined state because some other threads were monkeying around with memory at the time of the fork. So yeah, so the question is if I created 10 threads and within the run of all those 10 threads there was a fork, so if that happens, this rule still applies, but it would create 10 new processes and then each of those new processes have a single thread which would be a copy of whatever thread called it, right, so good question and we could fork bomb ourselves even faster if we just had our loop inside of that. Yeah, so that is like a really hard thing. So there's also this code that we won't cover in this course but if you want ever find yourself forking in a thread you're gonna find like weird inconsistent state but you can use this thing called pthread app fork to control what happens when a fork occurs so that you can leave your memory in some consistent state before the fork so that both the new process will have some, at least some consistent view of memory but that's not gonna be covered in this course, you don't have to know about that, that's kind of just a fun thing, I've never had to use it, thank God because that would be awful. Oh yeah. Yeah, so that new, sorry, that new process would be a single thread could be within our run, right? That normally implicitly calls pthread exit or you could call pthread exit so because it's the only thread now if you call pthread exit it's going to end the process and by default it just always returns error code zero but in the new child process you could of course just call exit yourself and return whatever error code you want. Okay, so signals are other fun complication so if I have a process with say eight threads and a signal gets sent to it, well what happens? So what Linux will do is just kind of pick a random thread and have that thread handle the signal so this makes concurrency kind of hard so you have to consider any other, or you have to consider any thread being interrupted at any time to run your signal handler code so you don't know if it's the main thread, you don't know if it's the thread you create, you have absolutely no control over it and this kind of gets very hairy. Yep, yeah so it would pick a running thread if there's one running or one that could run if others are blocked. So the question is is there any way to politely suggest that it gives a signal to the main thread? Not as far as I know, there's other ways around it that will come way later so you can kind of force the issue on that but I don't think through the default signal stuff that you can do it but you don't have to worry about that until lab three where you actually have to deal with signals but the nice thing about signals for you in lab three is you have user level threads so you only have a single process so you know that your one process is going to be the thing that gets the signal so it's a bit nicer for you. Okay so this is the kind of default thing instead of having many to many one common technique is to use something called a thread pool so if the goal of many to many was just to avoid creation cost well I don't have to support many to many in my threading library, I could have a thread pool which just creates a certain number of threads and a queue of tests so maybe like I said before you wanna get the most parallelism you want and you would just create as many threads as CPUs in the system and then as requests come in you would just have a thread wake up then give them some work to do and then as soon as they're done that work they'd go back to sleep so you wouldn't actually destroy it it would just go back to sleep and then when there's a new task it would go ahead and do that task so you only create your threads once you reuse them over and over again when there's no work to do and that's one very common technique and that's called a thread pool so you might encounter this with one of the labs way later in the course but since you'll be implementing many to one our process life cycle still applies because essentially your thread is just the virtual CPU it's the actual execution of this so this is your state diagram that all of your threads will be using and then of course since this is a this is all user level threads below this because it's all running in a process this also happens at the process level right so if it takes a system call the system or the if it does a system call then the process will be blocked and then your threading library will have no idea that a system call is being executed it would just consider it as running so the code you have to implement in lab two you'll have to create a function called thread create which essentially will create a thread allocate some stack space initialize some structure that will hold all the registers so you can context switch and whenever you're done creating a thread you can just have a double ended queue that is just full of threads that are waiting or that can execute and whenever you're done creating a new thread you could put it at the end of that queue and then as part of your scheduler which is not going to be terribly sophisticated your scheduler is going to be responsible for taking tasks from waiting to running and in that case the easiest thing to do is just to pick a thread that is at the front of the queue because you can just assume it's like a line at Disney World or something like that and it gets to ride next so that would be the thread to run and then in lab two remember we had cooperative processes or cooperative scheduling so you'll have the same thing in lab two you'll have cooperative threads so the only way for a thread to give up the CPU is that thread has to explicitly call thread yield and that will transition that thread from running to waiting so it'll essentially just put it back to the end of the line so that, yeah, it'll put it to the end of the line and then your threading library would just pick the next thread to run from the front and start running that, yep, yep so it depends where the context switch is happening so in our case we're doing user level threads so you're going to have to do the context switch yourself but there'll also be, right there'll also be another context switch under that because the process the kernel knows about will be context switched in and out too yeah, yeah, so you'll, you're essentially just creating fake threads, right so thankfully you don't have to, you don't have to take away the CPU from any thread in lab two, they have to essentially relinquish it by using thread yield but of course any thread can just not call thread yield until it is done in which case it would just hog the entire CPU so the other transition you'll have to make is from running to block and then you implement something called thread sleep which just basically makes the thread not runnable anymore so it can't be transitioned to the running state and then eventually some other thread will call thread wake up which will just put it back into that waiting queue at the end of the line again and then you'll have to implement of course thread exit so the running thread can call thread exit which would essentially turn it into a zombie thread and it would be terminated at that point and I don't think you have to implement like a thread join as far as I know there's a thread destroy but there's no join okay, so like I said the scheduler can just be some simple round robin thing so you just create a queue that always runs the thread at the front of the queue and then when it yields it just or a new threads created it's just always added to the back of the queue so you'll have to do the context switch and again you'll have to save the registers you'll, the first hurdle you'll probably encounter is saving the program counter you have to monkey with it a little bit and kind of really think about it because otherwise if you save the program counter at the state it's at it will go ahead and whenever you restore it it will restore it to right before it saved itself and it will just save itself again and you'll get into this very nasty loop so that's one thing you'll have to be careful of and again these are cooperative threads so they have to play nice and in lab three you'll do the preemptive version where your threading library will actually steal CPU away from a thread and force it to context switch yeah you'll be saving them and creating a stack okay so yeah okay so that's a good question the question is when thread is running what's the difference between sleep and yield the difference is that if you yield it will just go back to the waiting task and it could be run immediately again it's still eligible for being run while if you call sleep it's in this block state and block just means it's not eligible to run so even if the CPU is idle it still doesn't run so of course you can think you can brick your process if every thread goes to sleep and it's all blocked then you can't make any progress anymore because no thread will actually wake up okay all right yeah yeah so the question is if a thread puts itself to sleep how does it get unblocked and the answer to that is another thread has to wake it up yep because otherwise you can't run again so you can't wake yourself back up okay all right well let's get into our next fun complication then and kind of review threads a bit more and just play around with them so we'll create a program that spawns eight threads and each thread will increment a value 10,000 times so if the initial value of that variable is zero what should the end result be? 80,000 but not right so we'd expect to see 80,000 so let's go ahead and kind of practice some more threads and see an actual bigger join example so here's my main in main I create an array of pthread types which again processes and threads are kind of analogous to each other so if it's easier you can think of that pthread type as just a thread ID just like you'd think of the return value of fork as a process ID so if that's easier you can think of this as a thread ID so I declare an array for all my threads that has space for num threads which in this case is eight and then I have a for loop which goes ahead and creates the eight threads and gives it the memory address the second value is null so they're going to be a joinable thread because that is the default value we're going to have them all run this run function and we're not going to pass an argument because we don't care yep, yes, yeah so that's a good point he brought up the point that in total right after this point I will have nine threads because again a process is going to be created and there's going to be a thread that runs main so main will come here and then create eight more threads so in total I will have nine threads and that is such a good question it'll probably be on the quiz if the other class knows that by now which they might not okay so anyways let's see the run function oh first to start off who knows what the static means because I, yeah which sounds like a yeah so what's the difference between this and a global variable yeah yeah so basically without getting into compiler nonsense basically this is a global variable right this line and if you put static in front of it it still behaves as a global variable but you can think of it as you can only access that global variable from this C file and you can't access it from another C file so it's kind of like a global variable that other people can't monkey around with so you're reasonably sure that it won't change out from under you okay well to make that even worse so int i that is a stack variable right it's just allocated on the stack who wants to tell me what that means what what do they teach you in the C course alright they taught us nothing in the C course so in this course right knowing what's on the stack and what's in the heap and what's a global variable is kind of important especially if we're in the same address space and we can monkey around with things so annoyingly so everyone agrees this is on the stack yeah so this essentially makes it a global variable so it will be a global variable and the only distinction here is that you can only access that global variable from within that function but otherwise it behaves exactly like a global variable so if i did this it would exist for the entirety of the program but because this is now threads each thread would use the same variable since that's a global variable and we'd have a disaster on our hands yep so global variables are stored when you load your program so they're just as part of some information the l file there's going to be a section that has a data section that says you know x should go in this spot of memory and it doesn't change throughout so it lives as long as the process lives so it is neither in the stack or the heap it's just in some predefined memory space and that's it yep yeah so the question is if i if some thread sets this variable to 10 and then another thread tries to read it what will it get and it will get 10 because it is a global variable so it's just got one single memory address that it points to the memory address will never change and whatever the value is because all the threads are in the same address space they'll all get the same value yep yeah so in this case static int i i can only access this i within this run function yeah within the scope of this yep yep okay so someone should have taught you that in the first year because now maybe it didn't really matter back then but now it really matters right because if i change it to static every thread can see that and if every thread is going through this loop i's not going to increment sequentially it's just going to be like just random values all the time they're going to fight with each other and it's going to be terrible all right so in this case i did int i yeah this one oh yeah counter i want to be global variable because we're going to see the fight okay so then after i create all the threads i would join them because i want to wait for all of them to finish right and i actually care about when they finish and then after they all finish then i can print my counter and be sure that all my threads have finished execution and this is a case where you would want joinable threads because if i had detached threads what would probably happen if i just had detached threads yeah yeah so if i just have a detached thread here and then print counter it's just going to rip through it it's going to create all the threads and then immediately just print that and then exit the process which will kill all the threads so likely this counter would be some low value because some of the other threads might not have even run yet and then main would exit and the process would die yep yeah yeah so p thread join is the exact same thing as like wait pid so it's going to wait for that thread to die the main thread is going to be blocked until one of the other threads dies all right so anyone tell me why i wouldn't do something like that why do i have two four loops why don't i just whoops anyone want to guess why i don't do something like that yep yeah yeah so in this case i want to have give the kernel the opportunity to paralyze this as much as possible so if i have something like this it's going to create a single thread then wait for it you know create a single thread wait for it to finish create the next thread wait for it to finish create the same thread wait for it to finish so i'm essentially just having a like only one thing is executing at a time so i basically just made a single threaded program with a lot more steps so if i do this i create all the threads so now at this point in my program i have nine threads right the main thread and then the eight other threads that i'm hoping that the kernel will schedule nicely for me and then they start dying off at pthread join because at this point there would only be one thread and it would be the main thread yeah so the question is what about pthread0 exited took way longer than all the other threads while pthread join would the first time it goes through this it would wait on thread zero so even if the other threads are done before it would have to wait to join on that specific thread to clean it up they'd all be zombies right so we just have seven zombie threads until the first thread finishes and then we just wait on or essentially just wait on all of them yep yeah so the question is is there an basically is there an equivalent of weight where i just say i don't care what thread finishes first just wake me up whenever any thread finishes and the answer to that is by default no so there's a there's a non-blocking version of join so you can probe it state to see if it's a zombie yet so you could do that but you'd have to pull and ask every thread over and over again but as far as i know there's no equivalent of just plain weight on anything okay so now we get to run this so if i run it i'm expecting 80 000 and of course when i run it 77 000 not bad i can run it a few times 72 of 57 yikes 60 66 50 oh we're getting worse hey we're bug-free right works for me so this again is why programming with this is very very is more difficult oops all right so every time through except for times i get insanely lucky i essentially just get a bunch of random values right hey so one question is this a way that programs create random values and the answer to that is no that they do something much smarter than this okay anyone can can anyone think of ways i could fix this even knowing what we know now okay if i want this to run in parallel still yeah if i don't have parallelism or concurrency things are easy because it's back to our old old life right yep oh yeah yeah so if this wasn't such a ridiculous example that's one good way to do it so you would make you know you could make counter a local variable there so that's unique to every thread they could all increment it so say it was something better than that and then as part of their return value they'd have to malloc some space to point to their integer and then within the join right so this would return some pointer to some int and then within the join we could actually capture the return value and then since we wrote the thread we know it's pointing to an integer so we could just add everything up from each individual thread in the main thread and that way we wouldn't have any issue so that is one good way to do it and then we'll see more ways next lecture but so any other questions about this yeah okay so we got time so let's just let's return some values so my fix I can say int local count this is like a very ridiculous thing to do but let's bear with me so I'll change counter to be local counter so now that's on the stack each thread it's all independent now right so then I'm incrementing local counter at the end of this I'm done so I could return an integer pointer because I can just cast it to avoid I'll call it return if I malox I'll be nice and say size of int so now that pointer is in the heap so if I return that it's going to still be valid right it's not like I'm oops oh I just so if I return that it's still valid why is that a compiler oops return to oh yeah semicolon 2 and return to 4c issue okay so at that point it's going to malock and return because if we did something like we returned local counter like that right that's what we did last time that's very very bad because as soon as the thread's done that function will be return it's out of scope it's some invalid or it's some kind of trash memory so we have to use memory so we'd malox some space on the stack or sorry yes so no that's good feel free to show it to me if I say something stupid so we allocated some memory on the heap and then we'd return our we'd write the value of our local counter there yep no maloch always just allocates on the heap so luckily for you the authors of maloch if multiple threads are calling maloch they won't fight over each other so so you'll get if you call if a thread calls maloch it's going to get a unique block of memory from whatever thread called it so each thread is going to because we have eight threads there's going to be eight maloch calls that are all going to be unique addresses and then each one just returns one address right okay so now we need to play with the return value so in join we of course have to allocate so this is kind of our return we just have to allocate some space on the on the stack to hold our return value and then we can give the address of the return value I know it's an int and then I probably have to void star star yeah whoops oh I didn't I need maloch yeah so I haven't added them up yet I just had to include the maloch thing all right so that gets it so then return is now a pointer and then within here I can do counter plus equals dereference ret and add them all up right that is a good point and since I am such a nice person I should also free the memory so there that should be what we have oh Jesus what I do yeah I need to cast the void pointer to an integer yeah no it's an integer pointer yeah what I do is it consistent yikes huh well that was a crappy example yes because it has to be a pointer to a pointer so it can write the value there yeah what I do no it's local counter yeah it should yeah that's uh really weird oh of course local counter is not initialized whew there we go okay I'm not that bad programming I'm just I'm just forgetful so 80,000 every single time okay whoever caught that very very good yeah so I didn't initialize local counter so it was just some random garbage oh okay yeah so the question is the one without malloc why did I get such random values and I would got the random values even in the case where I only had a single CPU so if I go back assume I had the wrestling code so plus plus counter it's deceptive that's a global variable so that's actually three operations so it has to load that global variable from memory and then to a register or something like that then it's going to increment that and that's going to be local to a thread and then it's going to have to write that value back out through memory so you can't even get the wrong value if you have two threads and you only add to it once so because there's concurrency threads can get interrupted at any time and you can't control it so the initial value is zero one thread can go ahead load that value from memory to register which would be zero then it could context switch to another thread that value hasn't changed yet it would load it from memory which it would get zero then at that point either thread could execute they would both increment it to one and then they would both write one to that memory location so instead of what we would expect it writes a one and then a two it would instead write a one and then a one so that's the crux of our problem and we'll get into that next lecture unless I have to do quiz review yeah so just remember processes curl threads enable parallelization threads can have or processes can have multiple threads that we saw a bunch of implementations that probably are that are valid for the quiz and then operating system gets some more complexities and now we have synchronization issues but hey we've showed how to solve it at least one way so just remember I'm pulling for you we're all in this together


forward of as a man thinketh this is a LibriVox recording all LibriVox recordings are in the public domain for more information or to volunteer please visit LibriVox.org recording by Andrea Fiori as a man thinketh by James Allen forward this little volume the result of meditation and experience is not intended as an exhaustive treaty on the much-written upon subject of the power of thought it is suggestive rather than explanatory its object being to stimulate men and women to the discovery and perception of the truth that they themselves are makers of themselves by virtue of the thoughts which they choose and encourage that mind is the master weaver both of the inner garment of character and the outer garment of circumstance and that as they may have here too woven in ignorance and pain they may now weave in enlightenment and happiness James Allen chapter 1 thought and character the aphorism as a man thinketh in his heart so is he not only embraces the whole of a man's being but is so comprehensive as to reach out to every condition and circumstance of his life a man is literally what he thinks his character being the complete sum of all his thoughts as the plant springs from and could not be without the seed so every act of a man springs from the hidden seeds of thought and could not have appeared without them this applies equally to those acts called spontaneous and unpremeditated as to those which are deliberately executed act is the blossom of thought and joy and suffering are its fruits thus does a man garner in the sweet and bitter fruited of his own husbandry thought in the mine hath made us what we are by thought was wrought and built if a man's mind hath evil thoughts pain comes on him as comes the wheel the ox behind if one endure impurity of thought joy follows him as his own shadow sure man is a growth by law and not a creation by artifice and cause and effect is as absolute and undeviating in the hidden realm of thought as in the world of visible and material things a noble and godlike character is not a thing of favor or chance but is the natural result of continued effort in right thinking the effect of long cherished association with godlike thoughts an ignoble and bestial character by the same process is the result of continued harboring of groveling thoughts man is made or unmade by himself in the armory of thought he forges the weapons by which he destroys himself he also fashions the tools with which he builds for himself heavenly mansions of joy and strength and peace by the right choice and true application of thought man ascends to the divine perfection by the abuse and wrong application of thought he descends below the level of the beast between these two extremes are all the grades of character and man is their maker and master of all the beautiful truths pertaining to the soul which have been restored and brought to light in this age none is more gladdening or fruitful of divine promise and confidence than this that man is the master of thought the molder of character and the maker and shaper of condition environment and destiny as a being of power intelligence and love and the Lord of his own thoughts man holds the key to every situation and contains within himself that transforming and regenerative agency by which he may make himself what he wills man is always the master even in his weakest and most abandoned state but in his weakness and degradation he is the foolish master who misgoverns his household when he begins to reflect upon his condition and to search diligently for the law upon which his being is established then he becomes the wise master directing his energies with intelligence and fashioning his thoughts to fruitful issues such as the conscious master and man can only thus become by discovering within himself the laws of thought which discovery is a total matter of application self analysis and experience only by much searching and mining or golden diamonds obtained and man can find every truth connected with his being if he will dig deep into the mine of his soul and that he is the maker of his character the molder of his life and the builder of his destiny may he unerringly prove if he will watch control and alter his thoughts tracing their effects upon himself upon others and upon his life in circumstances linking cause and effect by patient practice and investigation and utilizing his every experience even to the most trivial every day occurrence as a means of obtaining that knowledge of himself which is understanding wisdom and power in this direction as in no other is the law of absolute that he that seeketh findeth and to him that knocketh it shall be opened for only by patience practice and ceaseless importunity can a man enter the door of the temple of knowledge end of four word and chapter one recording by Andrea Fiori chapter two of as a man thinketh by James Allen this LibriVox recording is in the public domain recording by Andrea Fiori chapter two effect of thought on circumstances man's mind may be likened to a garden which may be intelligently cultivated or allowed to run wild but whether cultivated or neglected it must and will bring forth if no useful seeds are put into it then an abundance of useless weed seeds will fall therein and will continue to produce their kind just as a gardener cultivates his plot keeping it free from weeds and growing the flowers and fruits which he requires so may a man tend the garden of his mind weeding out all the wrong useless and impure thoughts and cultivating toward perfection the flowers and fruits of right useful and pure thoughts by pursuing this process a man sooner or later discovers that he is the master gardener of his soul the director of his life he also reveals within himself the laws of thought and understands with ever increasing accuracy how the thought forces and mind elements operate in the shaping of his character circumstances and destiny thought and character are one and as character can only manifest and discover itself through environment and circumstance the outer conditions of a person's life will always be found to be harmoniously related to his interstate this does not mean that a man's circumstances at any given time are an indication of his entire character but that those circumstances are so intimately connected with some vital thought element within himself that for the time being they are indispensable to his development every man is where he is by the law of being the thoughts which he has built into his character have brought him there and in the arrangement of his life there is no element of chance but always the result of a law which cannot air this is just as true as those who feel out of harmony with their surroundings as of those who are contented with them as a progressive and evolving being man is where he is that he may learn that he may grow and as he learns the spiritual lesson which any circumstance contains for him it passes away and gives place to other circumstances man is buffeted by circumstances so long as he believes himself to be the creature of outside conditions but when he realizes that he is a creative power and that he may command the hidden soil and seeds of his being out of which circumstances grow he then becomes the rightful master of himself that circumstances grow out of thought every man knows who has for any length of time practice self-control and self-purification for he will have noticed that the alteration in his circumstances has been an exact ratio with his altered mental condition so true is this that when a man earnestly applies himself to remedy the defects in his character and make swift and marked progress he passes rapidly through a succession of vicitudes the soul attracts that which it secretly harbors that which it loves and also that which it fears it reaches the height of its cherished aspirations it falls to the level of its unchaste and desires and circumstances are the means by which the soul receives its own every thought seeds sown or allowed to fall into the mind and to take root there produces its own blossoming sooner or later into act and bearing its own fruitage of opportunity in circumstance good thoughts bear good fruit bad thoughts bad fruit the outer world of circumstance shapes itself to the inner world of thought and both pleasant and unpleasant external conditions are factors which make for the ultimate good of the individual as the reaper of his own harvest man learns both by suffering and bliss following the inmost desires aspirations thoughts by which he allows himself to be dominated pursuing the willow the wisps of impure imaginings or steadfastly walking the highway of strong and high endeavor a man at last arrives at their fruition and fulfillment in the outer conditions of his life the laws of growth and adjustment everywhere obtains a man does not come to the almshouse or the jail by the tyranny of fate or circumstance but by the pathway of groveling thoughts and base desires nor does a pure-minded man fall suddenly into crime by stress of any mere external force the criminal thought had long been secretly fostered in the heart and the hour of opportunity revealed its gathered power circumstance does not make the man it reveals him to himself no such conditions can exist as descending into vice and its attendant sufferings apart from vicious inclinations or ascending into virtue and its pure happiness without the continued cultivation of virtuous aspirations and man therefore as the lord and master of thought is the maker of himself the shaper and author of environment even at birth the soul comes to its own and through every step of its earthly pilgrimage it attracts those combinations of conditions which reveal itself which are the reflection of its own purity and impurity its strength and weakness men do not attract that which they want but that which they are their whims fancies and ambitions are thwarted at every step but their inmost thoughts and desires are fed with their own food be it foul or clean the divinity that shapes our ends is in ourselves it is our very self only himself manacles man thought and action are the makers of fate they imprisoned being base and they are also the angels of freedom they liberate being noble not what he wishes and prays for does a man get but what he justly earns his wishes and prayers are only gratified and answered when they harmonize with his thoughts and actions in the light of this truth what then is the meaning of fighting against circumstances it means that a man is continually revolting against an effect without while all the time he is nourishing and preserving its cause in his heart that cause may take the form of a conscious vice or an unconscious weakness but whatever it is it stubbornly retards the efforts of its possessor and thus calls aloud for remedy men are anxious to improve their circumstances but they are unwilling to improve themselves they therefore remain bound the man who does not shrink from self-crucifiction can never fail to accomplish the object upon which his heart is set this is as true of earthly as of heavenly things even the man whose sole object is to acquire wealth must be prepared to make great personal sacrifices before he can accomplish his object and how much more so he who would realize a strong and well poised life here is a man who is wretchedly poor he is extremely anxious that his surroundings and home comfort should be improved yet all the time he shirks his work and considers he is justified in trying to deceive his employer on the grounds of insufficiency of his wages such a man does not understand the simplest rudiments of those principles which are the basis of true prosperity and is not only totally unfitted to rise out of his wretchedness but is actually attracting to himself a still deeper wretchedness by dwelling in and acting out indolent deceptive and unmanly thoughts here is a rich man who is the victim of a painful and persistent disease as the result of gluttony he is willing to give large sums of money to get rid of it but he will not sacrifice his gluttoness desires he wants to gratify his taste for rich and unnatural vines and have his health as well such a man is totally unfit to have health because he has not yet learned the first principles of a healthy life here is an employer of labor who adopts crooked measures to avoid paying the regulation wage and in hope of making larger profits reduces the wages of his work people such a man is altogether unfitted for prosperity and when he finds himself bankrupt both as regards reputation and riches he blames circumstances not knowing that he is the sole author of his condition i have introduced these three cases merely as illustrative of the truth that man is the causer though nearly always is unconsciously of his circumstances and that whilst aiming at a good end he is continually frustrating its accomplishment by encouraging thoughts and desires which cannot possibly harmonize with that end such cases could be multiplied and varied almost indefinitely but this is not necessary as the reader can if he so resolves trace the action of the laws of thought in his own mind in life and until this is done mere external facts cannot serve as a ground of reasoning circumstances however are so complicated thought is so deeply rooted and the conditions of happiness vary so vastly with individuals that a man's entire soul condition although it may be known to himself cannot be judged by another from the external aspect of his life alone a man may be honest in certain directions yet suffer provisions a man may be dishonest in certain directions yet acquire wealth but the conclusion usually formed that the one man fails because of his particular honesty and that the other prospers because of his particular dishonesty is the result of a superficial judgment which assumes that the dishonest man is almost totally corrupt and the honest man almost entirely virtuous in the light of a deeper knowledge and wider experience such judgment is found to be erroneous the dishonest man may have some admirable virtues which the other does not possess and the honest man obnoxious vices which are absent in the other the honest man reaps the good results of his honest thoughts and acts he also brings upon himself the sufferings which his vices produce the dishonest man likewise garners his own suffering and happiness it is pleasing to human vanity to believe that one suffers because of one's virtue but not until a man has extirpated every sickly bitter and impure thought from his mind and washed every sinful stain from his soul can he be in a position to know and declare that his sufferings are the result of his good and not of his bad qualities and on the way to yet long before he has reached that supreme perfection he will have found working in his mind and life the great law which is absolutely just and which cannot therefore give good for evil evil for good possessed of such knowledge he will then know looking back upon his past ignorance and blindness that his life is and always was justly ordered and that all his past experiences good and bad were the equitable outworking of his evolving yet unevolved self good thoughts and actions can never produce bad results bad thoughts and actions can never produce good results this is but saying that nothing can come from corn but corn nothing from nettles but nettles men understand this law in the natural world and work with it but few understand it in the mental and moral world though its operation there is just as simple and undeviating and they therefore do not cooperate with it suffering is always the effect of wrong thought in some direction it is an indication that the individual is out of harmony with himself with the law of his being the soul and supreme use of suffering is to purify to burn out all that is useless and impure suffering ceases for him who is pure there could be no object in burning gold after the dross has been removed and a perfectly pure and enlightened being could not suffer the circumstances which a man encounters with blessedness are the result of his own mental harmony blessedness not material possessions is the measure of right thought wretchedness not lack of material possessions is the measure of wrong thought a man may be cursed and rich he may be blessed and poor blessedness and riches are only joined together when the riches are rightly and wisely used and the poor man only descends into wretchedness when he regards his lot as a burden unjustly imposed indigents and indulgence are the two extremes of wretchedness they are both equally unnatural and the result of mental disorder a man is not rightly conditioned until he is a happy healthy and prosperous being and happiness health and prosperity are the result of a harmonious adjustment of the inner with the outer of the man with his surroundings a man only begins to be a man when he ceases to whine and revile and commences to search for the hidden justice which regulates his life and as he adapts his mind to that regulating factor he ceases to accuse others as the cause of his condition and builds himself up and strong and noble thoughts ceases to kick against circumstances but begins to use them as aids to his more rapid progress and as a means of discovering the hidden powers and possibilities within himself law not confusion is the dominating principle in the universe justice not injustice is the soul and substance of life and righteousness not corruption is the molding and moving force in the spiritual government of the world this being so man has but to write himself to find that the universe is right and during the process of putting himself right he will find that as he alters his thoughts toward things and other people things and other people will alter toward him the proof of this truth is in every person and it therefore admits of easy investigation by systematic introspection and self analysis let a man radically alter his thoughts and he will be astonished at the rapid transformation it will affect in the material conditions of his life men imagine that thought can be kept secret but it cannot it rapidly crystallizes into habit and habit solidifies into circumstance bestial thoughts crystallize into habits of drunkenness and sensuality which solidify into circumstances of destitution and disease in pure thoughts of every kind crystallize into innervating and confusing habits which solidify into distracting and adverse circumstances thoughts of fear doubt and indecision crystallize into weak unmanly and irresolute habits which solidify into circumstances of failure indigents and slavish dependence lazy thoughts crystallize into habits of uncleanliness and dishonesty which solidify into circumstances of foulness and beggary hateful and condemnatory thoughts crystallize into habits of accusation and violence which solidify into circumstances of injury and persecution selfish thoughts of all kinds crystallize into habits of self seeking which solidify into circumstances more or less distressing on the other hand beautiful thoughts of all kinds crystallize into habits of grace and kindness which solidify into genial and sunny circumstances pure thoughts crystallize into habits of temperance and self control which solidify into circumstances of repose and peace thoughts of courage self-reliance and decision crystallize into manly habits which solidify into circumstances of success plenty and freedom energetic thoughts crystallize into habits of cleanliness and industry which solidify into circumstances of pleasantness gentle and forgiving thoughts crystallize into habits of gentleness which solidify into protective and preservative circumstances loving and unselfish thoughts crystallize into habits of self-forgetfulness for others which solidify into circumstances of sure and abiding prosperity and true riches a particular train of thought persisted in be it good or bad cannot fail to produce this results on the character and circumstances a man cannot directly choose his circumstances but he can choose his thoughts and so indirectly yet surely shape his circumstances nature helps every man to the gratification of the thoughts which he most encourages and opportunities are presented which will most speedily bring to the surface both the good and evil thoughts let a man cease from his sinful thoughts and all the world will soften towards him and be ready to help him let him put away his weekly and sickly thoughts and opportunities will spring up on every hand to aid his strong resolves let him encourage good thoughts and no hard fate shall bind him down to wretchedness and shame the world is your kaleidoscope and the varying combinations of colors which at every succeeding moment it presents to you are the exquisitely adjusted pictures of your ever moving thoughts so you will be what you will be let failure find its false content in that poor word environment but spirit scorns it and is free it masters time it conquers space it cows that boastful trickster chance and bids the tyrant circumstance uncrown and fills a servant's place the human will that force unseen the offspring of a deathless soul can hew away to any goal the walls of granite intervene be not impatient in delays but wait as one who understands when spirit rises and commands the gods are ready to obey end of chapter two recording by andrea fiori chapter three of as a man thinketh by james allen this liber vox recording is in the public domain recording by andrea fiori chapter three effect of thought on health and the body the body is the servant of the mind it obeys the operations of the mind whether they be deliberately chosen or automatically expressed at the bidding of unlawful thoughts the body sinks rapidly into disease and decay at the command of glad and beautiful thoughts it becomes clothed with youthfulness and beauty disease and health like circumstances are rooted in thought sickly thoughts will express themselves through a sickly body thoughts of fear have been known to kill a man as speedily as a bullet and they are continually killing thousands of people just as surely the less rapidly the people who live in fear of disease are the people who get it anxiety quickly demoralizes the whole body and it lays open to the entrance of disease while impure thoughts even if not physically indulged will soon shatter the nervous system strong pure and happy thoughts build up the body and vigor and grace the body is a delicate and plastic instrument which responds readily to the thoughts by which it is impressed and the habits of thought will produce their own effects good or bad upon it men will continue to have impure and poisoned blood so long as they propagate unclean thoughts out of a clean heart comes a clean life and a clean body out of a defiled mind proceeds a defiled life and a corrupt body thought is the fount of action life and manifestation make the fountain pure and all will be pure change of diet will not help a man who will not change his thoughts when a man makes his thoughts pure he no longer desires impure food clean thoughts make clean habits the so-called saint who does not wash his body is not a saint he who has strengthened and purified his thoughts does not need to consider the malevolent microbe if you would protect your body guard your mind if you would renew your body beautify your mind thoughts of malice envy disappointment despondency rob the body of its health and grace a sour face does not come by chance it is made by sour thoughts wrinkles that marr are drawn by folly passion and pride i know a woman of ninety six who has the bright innocent face of a girl i know a man well under middle age whose face is drawn into inharmonious contours the one is the result of a sweet and sunny disposition the other is the outcome of passion and discontent as you cannot have a sweet and wholesome abode unless you admit the air and sunshine freely into your rooms so a strong body and a bright happy or serene countenance can only result from the free admittance into the mind of thoughts of joy and goodwill and serenity on the faces of the aged there are wrinkles made by sympathy others by strong and pure thought and others are carved by passion who cannot distinguish them with those who have lived righteously age is calm peaceful and softly mellowed like the setting sun i have recently seen a philosopher on his deathbed he was not old except in years he died as sweetly and peacefully as he had lived there is no physician like a cheerful thought for dissipating the ills of the body there is no comforter to compare with goodwill for dispersing the shadows of grief and sorrow to live continually in thoughts of ill will cynicism suspicion and envy is to be confined in a self-made prison hole but you think well of all to be cheerful with all to patiently learn to find the good in all such unselfish thoughts are the very portholes of heaven and to dwell day by day in thoughts of peace toward every creature will bring a bounding peace to their possessor end of chapter three recording by andrea fury chapter four of as a man thinketh by james allen this liber box recording is in the public domain recording by andrea fury chapter four thought and purpose until thought is linked with purpose there is no intelligent accomplishment with the majority the bark of thought is allowed to drift upon the ocean of life aimlessness is a vice and such drifting must not continue for him who would steer clear of catastrophe and destruction those who have no central purpose in their life fall an easy prey to petty worries fears troubles and self pittings all of which are indications of weakness which lead just as surely as deliberately plan sins though by a different route to failure unhappiness and loss for weakness cannot persist in a power evolving universe a man should conceive of a legitimate purpose in his heart and set out to accomplish it he should make this purpose the centralizing point of his thoughts it may take the form of a spiritual ideal or it may be a worldly object according to his nature at the time being but whichever it is he should steadily focus his thought forces upon the object which he has set before him he should make this purpose his supreme duty and should devote himself to its attainment not allowing his thoughts to wander away into ephemeral fancies longings and imaginings this is the royal road to self control and true concentration of thought even if he fails again and again to accomplish his purpose as he necessarily must until weakness is overcome the strength of character gained will be the measure of his true success and this will form a new starting point for future power and triumph those who are not prepared for the apprehension of a great purpose should fix the thoughts upon the faultlessness performance of their duty no matter how insignificant their task may appear only in this way can the thoughts be gathered and focused and resolution and energy be developed which being done there is nothing which may not be accomplished the weakest soul knowing its own weakness and believing this truth that strength can only be developed by effort and practice will thus believing at once begin to exert itself and adding effort to effort patience to patience and strength to strength will never cease to develop and will at last grow divinely strong as the physically weak man can make himself strong by careful and patient training so the man of weak thoughts can make them strong by exercising himself into right thinking to put away aimlessness and weakness and to begin to think with purpose is to enter the ranks of those strong ones who only recognize failure as one of the pathways to attainment who make all conditions serve them and who think strongly attempt fearlessly and accomplish masterfully having conceived of his purpose a man should mentally mark out a straight pathway to its achievement looking neither to the right nor the left doubts and fears should be rigorously excluded they are disintegrating elements which break up the straight line of effort rendering it crook ineffectual useless thoughts of doubt and fear never accomplished anything and never can they always lead to failure purpose energy power to do and all strong thoughts cease when doubt and fear creep in the will to do springs from the knowledge that we can do doubt and fear are the great enemies of knowledge and he who encourages them who does not slay them thoughts himself at every step he who has conquered doubt and fear has conquered failure his every thought is allied with power and all difficulties are bravely met and wisely overcome his purposes are seasonably planted and they bloom and bring forth fruit which does not fall prematurely to the ground thoughts allied fearlessly to purpose become creative force he who knows this is ready to become something higher and stronger than a mere bundle of wavering thoughts and fluctuating sensations he who does this has become the conscious an intelligent wielder of his mental powers end of chapter four recording by andrea fiori chapter five of as a man thinketh by james allen this liber box recording is in the public domain recording by andrea fiori chapter five the thought factor in achievement all that a man achieves and all that he fails to achieve is the direct result of his own thoughts in a justly ordered universe where loss of equipoise would mean total destruction individual responsibility must be absolute a man's weakness and strength purity and impurity are his own and not another man's they are brought about by himself and not another and they can only be altered by himself never by another his condition is also his own and not another man's his suffering and his happiness are evolved from within as he thinks so he is as he continues to think so he remains a strong man cannot help a weaker unless that weaker is willing to be helped and even then the weak man must become strong of himself he must by his own efforts develop the strength which he admires in another none but himself can alter his condition it has been usual for men to think and to say many men are slaves because one is an oppressor let us hate the oppressor now however there is amongst an increasing few a tendency to reverse this judgment and to say one man is an oppressor because many are slaves let us despise the slaves the truth is that oppressor and slave are cooperators in ignorance and while seeming to afflict each other are in reality afflicting themselves a perfect knowledge perceives the action of law in the weakness of the oppressed and the misapplied power of the oppressor a perfect love seeing the suffering which both states entail condemns neither a perfect compassion embraces both oppressor and depressed he who has conquered weakness and has put away all selfish thoughts belongs neither to oppressor nor oppressed he is free a man can only rise conquer and achieve by lifting up his thoughts he can only remain weak and object and miserable by refusing to lift up his thoughts before a man can achieve anything even in worldly things he must lift his thoughts above slavish animal indulgence he may not in order to succeed give up all animality and selfishness by any means but a portion of it must at least be sacrificed a man whose first thought is bestial indulgence could neither think clearly nor plan methodically he could not find and develop his latent resources and would fail in any undertaking not having commenced to manfully control his thoughts he is not in a position to control affairs and to adopt serious responsibilities he is not fit to act independently and stand alone but he is limited only by the thoughts which he chooses there can be no progress no achievement without sacrifice and a man's worldly success will be in the measure that he sacrifices his confused animal thoughts and fixes his mind on the development of his plans and the strengthening of his resolution and self-reliance and the higher he lifts his thoughts the more manly upright and righteous he becomes the greater will be his success the more blessed and enduring will be his achievements the universe does not favor the greedy the dishonest the vicious although on the mere surface it may sometimes appear to do so it helps the honest the magnanimous the virtuous all the great teachers of the ages have declared this in varying forms and to prove and know it a man has but to persist in making himself more and more virtuous by lifting up his thoughts intellectual achievements are the result of thought consecrated to the search for knowledge or for the beautiful and true in life in nature such achievements may be sometimes connected with vanity and ambition but they are not the outcome of those characteristics they are the natural outgrowth of long and arduous effort and of pure and unselfish thoughts spiritual achievements are the consummation of holy aspirations he who lives constantly in the conception of noble and lofty thoughts who dwells upon all that is pure and unselfish will as surely as the sun reaches its zenith and the moon it's full become wise and noble and character and rise into a position of influence and blessedness achievement of whatever kind is the crown of effort by the aid of self-control resolution purity righteousness and well-directed thought a man ascends by the aid of animality indolence impurity corruption and confusion of thought a man descends a man may rise to high success in the world and even to lofty altitudes in the spiritual realm and again descend into weakness and wretchedness by allowing arrogant selfish and corrupt thoughts to take possession of him victories attained by right thought can only be maintained by watchfulness many give way when success is assured and rapidly fall back into failure all achievements whether in the business intellectual or spiritual world are the result of definitely directed thought are governed by the same law and are of the same method the only difference lies in the object of attainment he who would accomplish little must sacrifice little he who would achieve much must sacrifice much and he who would attain highly must sacrifice greatly end of chapter five recording by andrea fiori chapter six of as a man thinketh by james allen this libra vox recording is in the public domain recording by andrea fiori chapter six visions and ideals the dreamers are the saviors of the world as the visible world is sustained by the invisible so men through all their trials and sins and sorted vocations are nourished by the beautiful visions of their solitary dreamers humanity cannot forget its dreamers it cannot let their ideals fade and die it lives in them it knows them as the realities which it shall one day see and know composer sculptor painter poet prophet sage these are all the makers of the afterworld the architects of heaven the world is beautiful because they have lived without them laboring humanity would perish he who cherishes a beautiful vision a lofty ideal in his heart will one day realize it columbus cherished a vision of another world and he discovered it capurnicus fostered the vision of a multiplicity of worlds in a wider universe and he revealed it buddha beheld the vision of a spiritual world of stainless beauty and perfect peace and he entered into it cherish your visions cherish your ideals cherish the music that stirs in your heart the beauty that forms in your mind the loveliness that drapes your purest thoughts for out of them will grow all delightful conditions all heavenly environment of these if you but remain true to them your world will at last be built the desire is to obtain to aspire to to achieve shall man's basis desires receive the fullest measure of gratification and his purest aspiration star for lack of sustenance such as not a law such a condition of things can never obtain ask and receive dream lofty dreams and as you dream so shall you become your vision is the promise of what you shall one day be your ideal is the prophecy of what you shall at last unveil the greatest achievement was at first and for a time a dream the oak sleeps in the acorn the bird waits in the egg and in the highest vision of the soul a waking angel stirs dreams are the seedlings of realities your circumstances may be uncongenial but they shall not long remain so if you perceive an ideal and strive to reach it you cannot travel within and stand still without here is a youth hard pressed by poverty and labor can find long hours in an unhealthy workshop unschooled and lacking all the arts of refinement but he dreams of better things he thinks of intelligence of refinement of grace and beauty he conceives of mentally builds up an ideal condition of life the vision of wider liberty and a larger scope takes possession of him unrest urges him to action and he utilizes all his spare time and means small though they are to the development of his latent powers and resources very soon so altered has his mind become that the workshop can no longer hold him it has become so out of harmony with his mentality that it falls out of his life as a garment is cast aside and with the growth of opportunities which fit the scope of his expanding powers he passes out of it forever years later we see this youth as a full grown man we find him a master of certain forces of the mind which he wields with worldwide influence and almost unequaled power in his hands he holds the cords of gigantic responsibilities he speaks and low lives are changed men and women hang upon his words and remold their characters and son like he becomes the fixed and luminous center round which innumerable destinies revolve he has realized the vision of his youth he has become one with his ideal and you too youthful reader will realize the vision not the idle wish of your heart be it base or beautiful or a mixture of both for you will always gravitate toward that which you secretly most love into your hands will be placed the exact results of your own thoughts you will receive that which you earn no more no less whatever your present environment may be you will fall remain or rise with your thoughts your vision your ideal you will become as small as your controlling desire as great as your dominant aspiration in the beautiful words of Stanton Kirkham Davis you may be keeping accounts and presently you shall walk out of the door that for so long has seemed to you the barrier of your ideals and shall find yourself before an audience the pen still behind your ear the ink stains on your fingers and then and there shall pour out the torrent of your inspiration you may be driving sheep and you shall wander to the city open mouth shall wander under the intrepid guidance of the spirit into the studio of the master and after a time he shall say i have nothing more to teach you and now you have become the master who did so recently dream of great things while driving sheep you shall lay down the saw and the plane to take upon yourself the regeneration of the world the thoughtless the ignorant and the indolent seeing only the apparent effects of things and not the things themselves talk of luck of fortune and of chance seeing a man grow rich they say how lucky he is observing another become intellectual they exclaim how highly favored he is and noting the saintly character and wide influence of another they remark how chance aids him at every turn they do not see the trials and failures and struggles which these men have voluntarily encountered in order to gain their experience have no knowledge of the sacrifices they have made of the undaunted efforts they have put forth of the faith they have exercised that they might overcome the apparently insurmountable and realize the vision of their heart they do not know the darkness and the heartaches they only see the light and joy and call it luck they do not see the long and arduous journey but only behold the pleasant goal and call it good fortune they do not understand the process but perceive the result and call it chance in all human affairs there are efforts and there are results and the strength of the effort is the measure of the result chance is not gifts powers material intellectual and spiritual possessions are the fruits of effort they are thoughts completed objects accomplished visions realized the vision that you glorify in your mind the ideal that you enthrone in your heart this you will build your life by this you will become end of chapter six recording by Andrea Fiori chapter seven of as a man thinketh by James Allen this Librabop's recording is in the public domain recording by Andrea Fiori chapter seven serenity calmness of the mind is one of the beautiful jewels of wisdom it is the result of long and patient effort and self control its presence is an indication of ripened experience and of a more than ordinary knowledge of the laws and operations of thought a man becomes calm in the measure that he understands himself as a thought evolve being for such knowledge necessitates the understanding of others as the result of thought and has he develops a right understanding and sees more and more clearly the internal relations of things by the action of cause and effect he ceases to fuss and fume and worry and grief and remains poised steadfast serene the calm man having learned how to govern himself knows how to adapt himself to others and they in turn reverence his spiritual strength and feel that they can learn of him and rely upon him the more tranquil a man becomes the greater is his success his influence his power for good even the ordinary trader will find his business prosperity increase as he develops a greater self control and equanimity for people will always prefer to deal with a man whose demeanor is strongly equitable the strong calm man is always loved and revered he is like a shade giving tree in a thirsty land or a sheltering rock in a storm who does not love a tranquil heart a sweet tempered balanced life it does not matter whether it rains or shines or what changes come to those possessing these blessings for they are always sweet serene and calm that exquisite poise of character which we call serenity is the last lesson of culture the fruitage of the soul it is as precious as wisdom more to be desired than gold than even fine gold how insignificant near money seeking looks in comparison with the serene life a life that dwells in the ocean of truth beneath the waves beyond the reach of tempestus in the eternal calm how many people we know who sour their lives who ruin all that is sweet and beautiful by explosive tempers who destroy their poise of character and make bad blood it is a question whether the great majority of people do not ruin their lives and mar their happiness by lack of self control how few people we meet in life who are well balanced who have that exquisite poise which is a characteristic of the finished character yes humanity surges with uncontrolled passion it is tumultuous with ungoverned grief is blown about by anxiety and doubt only the wise man only he whose thoughts are controlled and purified makes the winds and the storms of the soul obey him tempest toss souls wherever ye may be under whatsoever conditions ye may live know this in the ocean of life the aisles of blessedness are smiling and the sunny shore of your ideal awaits your coming keep your hand firmly upon the helm of thought in the bark of your soul reclines the commanding master he does but sleep wake him self control is strength right thought is mastery calmness is power say unto your heart peace be still end of chapter seven recording by andrea fiori end of as a man thinketh by james allen


Over to I'm Amis the Steve Rhodes as we do each and every Monday at 20 past the hour and don't forget folks He doesn't outstanding show here every trading day 11 11 to 12 Eastern standard time also a great newsletter mastering probability now It's very easy to get his newsletter come over to our website at TFNN You're going to newsletters. You see mastering probability right on the right-hand side You just hit that mastering probability you hit subscribe you can get mastering probability for one month for $149 you get it for six months for 695 which is a savings of $199 22% and you can get it for one year for 11 95 which is a savings of $593 and 20 or 33% now folks bottom line. We have a trade is marketing man. I mean big time So come over check it out You can basically get it for 29 days free. It's a 30-day money back guarantee and you'll be happy if you did Steve Rhodes What's going on? Well, we're so glad that you folks in Tampa beat one Storm hurricane Ian pretty heavy lost but then lost to the storm that blew in by Kansas City. I know Yeah, what are we gonna do those games? Yes, they were unbelievable, man And I love the Holmes anyway, so it's terrible because I like Brady too, so it's like no I mean that that kid something else man. Well, they're both something else But he is well, you know when he gets on I think you know, I think he's best when he's out of the pocket Yeah, you know talking.  I mean seriously I mean Amazing, absolutely amazing So the question everybody's got today including myself is that the stock market just make a bottom So I thought what we could do is kind of focus it on the dial Okay, just take a look at the chart patterns out there and see what they say so let's start with the Dow's 125 year mid-term election cycle pattern. Okay, and if we take a look at that pattern That's what we have up on the screen right now the red vertical line that represents where we're at today And I'd have to say and taking a look at this chart the answer to the question would be yes And this would also suggest not that we won't see ups and downs pullbacks But this would suggest at the market the Dow itself could run higher right into election day November the 8th out there So that's coming from the seasonal cycle chart However, if we take a look at last Friday's price action That was a second consecutive weekly close below. It's a June swing point out there Okay, that really triggers an A to B equal CD to the downside with the first price projection level being about 268 69 248 now what folks can also take a look at as price was moving below the B point on a this is a weekly chart Yes, so we're looking at as price was moving below the week the weekly swing point It was with lighter volume So always makes that a to B equal CD to the downside a little bit suspect now for the Dow cash index that same pattern It's weekly a to B equal CD to the downside would look like this And this here the a to B equal CD we can see the one-to-one would take us to 269 82 But if we look at the retracement from the 2020 lows to the highs out here in 2022 Well, we'll see is that point six rate retracement is a 1 to 1.272 a to B equal CD pattern And that would suggest that would then potentially form a Gartley by pattern So we've got mixed signals out here if we take a look at the shorter term This is the Dow This is suggesting that the Dow may have bottomed as price found support at a descending price channel Now what I've done here, Tom is I've taken the the the tools at Bud Rolfe's taught to us I'm taking a look at the open and closes of candles to create that channel line So the top of that channel line is very very solid. I believe the bottom of the channel line is also solid We can see that price got down there And this is suggesting that we could see price move up to either the midpoint of this descending price channel or Make its way all the way up to the top of that and that signals that we should see a further rally Now we can also take the Dow's what so those were diagonal price channels out there We also look at horizontal price channels, and that's what these green lines show So at the same time the price was hitting the bottom of that descending price channel Well, we can also see his price was finding support in the air of 28 9 0 9 That was the next horizontal trading range boundary line So this suggests or supports the idea that we could see a short-term bottom with a further counter trend move and if price But however, if price takes out the lows of last Friday out here What the real signal would be telling us is that price is busting through this descending price channel out here It would likely this is a much bigger picture. Yes This takes us back to 2009 the yellow lines are the rising price channels that we have been in here And so a bust of the lows from last Friday would suggest their price moves down to about the 26,500 Area and that's where we've got this next rising yellow Diagonal line to the upside From a daily standpoint if we take a look at the Dow equity future contract and I took a snapshot of this Probably about 10 15 minutes ago. We're definitely gonna get a bullish engulfing candle now This is a daily a to b equal CD pattern and where price got to earlier This week or today this morning was the 1 to 1.272 levels have got below the lows from last week We now have a bullish engulfing candle We also have we take a look at the expansion of swing points here from the June lows to the highs that we saw out here in The August time frame. We've got a 1.272 expansion that took us to the 28 594 level so this gives us a Gertley buy pattern and this would suggest that price This is the Dow Dow equity future contract folks This would suggest that price may want to move to either 35 45 or 31 256 Those happen to be the center and top of their bearish structured daily profile So this is going to be a sell zone 3545 to 31 256 and if that run is going to unfold Well, then what we needed to see today, and I don't know where we're at right now again This was a snapshot from about 15 minutes ago. We need to see price close above this red green line That's referred to Tom as the oscillator and change line We've only seen since the move lower back around the 22nd We've only seen two bars that have actually closed above this line So today could be bar number one today could be bar number two if we get beyond that Then that's supporting that run to this 31 256 level that I had referred to just before So in overnight trading so we take a look at a number of different time frames So weekly charts say hey you busted through those June lows It was on light volume, but be prepared for a potential a to b equal CD to the downside We did hit some support some a descending trend line channel support out there the daily time frame is giving us a Gartley butterfly pattern out here Now we switch down or I switch down into shorter term time frames and the two-hour time frame chart and In a real key as to whether now we've made any kind of bottom of significance here with a rally That could take us up into election day is going to be how this first retracement takes place Do we get a do no do we start to form? Higher bottoms and higher highs out there well the two-hour chart is one that I'll be paying attention to tonight And the reason that is Tom is because it's going to complete what I refer to as a teeny nine count top By day's end okay as the equity future contract comes to close typically when we get teeny nine counts We will see a retracement The question is do we see a retracement back to support the top of the profile on a two-hour time frame? That's a twenty nine four thirty two or do we get a pullback all the way to the oscillator and change line Which is likely out here now these patterns they help us to identify when potential tops or bottoms form They don't always work meaning that we could see a top It just was a sideways move and then price continues to move higher and a price takes out overnight twenty nine seven eighty four That adds to the idea that we should see a further Countertrend move out there, so it's going to be the two-hour time frame chart to be watching overnight for those folks that Watch the future contracts out there and folks Bottom line is traders market. So if you'd like to trade come over to our website at TF and Hit the newsletter go on the right-hand side. You see maximum probability right there. Steve does a great job lines everything up every morning, I mean You got a lot of volatility man, you do you do and I'll just last I lastly I posted up this little chart here This is a market analyzer to it evaluates what the market conditions are for all these different time frames You can see on the dailies for the mining sector. It's showing the bear market is over inside the mining sector Well, I like that. Yes, you do I give it a big kiss Great one is safe one look for the show tomorrow Steve eggs time. Thank you