JohnOne Posted March 2, 2016 Share Posted March 2, 2016 (edited) Over the past few years I've had a general idea of how computers work, thanks to a lot on info on the internet. It is my understanding that bits are passed around, instructions are given and carried out and all that electron jazz. But I don't understand why race conditions for memory access are reached. I read an article recently in which the author mentioned that a CPU only carries out one instruction at a time, meaning linear, and that is regardless of how many cores it might have. I'm sorry I cannot remember the source of the article, it was some techno website, and I just considered it to be true because it made sense as I was reading it. So if it is true, why ever does a race condition between processes or threads occur? An instruction is received by the cpu from some software to read memory at 000000324, the next instruction is received from different software to read the same, in a linear world there should be no race. I don't get it. What am I missing? EDIT: If I'm wrong about the cores part, please just consider a single core processor. Edited March 2, 2016 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
TheSaint Posted March 2, 2016 Share Posted March 2, 2016 My understanding is that it is to do with pipes, bottlenecks and timing, Which to me, means you can have simultaneous processes occurring (cores), but then they share output and input pathways, and that is where timing comes into it. First come first served is where I imagine the racing occurs. I am however far from being an expert, and so could be completely wrong in what my mind has pieced together, from things I have read and what seems logical. It has also been some time between readings ... usually only when considering my next PC. I have forgotten for instance, where the Southbridge fits into all that ... just remember it improves things in that regard ... alternate pathways or something. My advice, is don't get old ... you forget or misremember things ..... oops too late. JohnOne and Autoyt443 2 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
jaeger52 Posted March 2, 2016 Share Posted March 2, 2016 JohnOne, I was intrigued by your question as I realized i did not know the answer either, and I id a little poking around. I think TheSaint is correct about the correlation between race conditions and bottlenecking. It's definitely a timing issue, and bottlenecking could cause enough chaos to have threads run in the wrong sequence, throwing the error. JohnOne 1 Link to comment Share on other sites More sharing options...
trancexx Posted March 2, 2016 Share Posted March 2, 2016 Race condition on level of cpu doesn't exist in "normal" mode. It can happen with overclocking when components that form logic circuits fail to change state fast enough. JohnOne, I believe you mean operating systems, rather than computers in general. That's where racing conditions can occur, because that's where (artificial) time slicing starts. It's level above CPU. JohnOne 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
RTFC Posted March 2, 2016 Share Posted March 2, 2016 This might clarify. JohnOne and TheSaint 2 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
jaberwacky Posted March 2, 2016 Share Posted March 2, 2016 It seems to me that you would be interested in the dining philosophers problem. JohnOne and TheSaint 2 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
TheSaint Posted March 3, 2016 Share Posted March 3, 2016 Ha Ha, good one Jabbers. Don't you just love logic puzzles. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
JohnOne Posted March 3, 2016 Author Share Posted March 3, 2016 Great stuff ladies and gentlemen. So given all the info above, is it safe to say to a layman that race conditions occur because, despite a cpu making linear computations, the speed at which a bit is read cannot be guranteed, perhaps due to the path an electron might take to reach its destination, which is why timing is important? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted March 3, 2016 Author Share Posted March 3, 2016 Yes thanks trancexx I should have written OS or software, it is what I meant. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kcvinu Posted March 3, 2016 Share Posted March 3, 2016 dining philosophers .. I am hearing this first time. Read that article. Thanks @jaberwacky Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only) Link to comment Share on other sites More sharing options...
Popular Post trancexx Posted March 3, 2016 Popular Post Share Posted March 3, 2016 9 hours ago, JohnOne said: Great stuff ladies and gentlemen. So given all the info above, is it safe to say to a layman that race conditions occur because, despite a cpu making linear computations, the speed at which a bit is read cannot be guranteed, perhaps due to the path an electron might take to reach its destination, which is why timing is important? But that's not it. When you start Windows you actually start a program (I'll underline it from now on). That program is the only thing that ever "touches" your computer's CPU. Then that program creates interface for you (the user) to start application(s). At the same time the program creates time slots in which it then puts tasks. Time slot is a portion of overall time. The program doesn't advertise how big one time-slot is. It can be two ticks, 1 millisecond, 6 instructions, or whatnot. This is done to create impression that it runs more things at the same time. It actually runs only one thing at any given time, but switches too fast for you to notice it. When mentioned applications are "started" the program puts it into one time slot. Sometimes these slots are divided into sub-slots (working threads) of a process. When one time-slot is "active" the program takes binary data (opcodes) from the application and "pushes" it to the CPU onto its behalf. Race condition can occur, for example, if the program has bug and allows two slots to overlap. This usually ends up with BSOD. More common and usual case of race condition occurring is when programmer asks the program to create sub-slots (threads) and then access the same addresses from two different sub-slots. Because the program didn't say for how long one sub-slot will run, it can happen that one sub-slot runs for longer time than another before execution is switched to another sub-slot. First slot might have executed more instructions. The problem for the code in another sub-slot is that the code from the first one may have changed data at the shared addresses. Then that other thread continues, but has no idea that the data it works on has been changed by someone else. Now, that is it in layman's terms. JohnOne, iamtheky, jaeger52 and 2 others 5 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
jaeger52 Posted March 3, 2016 Share Posted March 3, 2016 Great rundown, trancexx. That makes a lot more sense to me now! Link to comment Share on other sites More sharing options...
Guest Posted March 3, 2016 Share Posted March 3, 2016 (edited) I created a very basic example of the race condition bug with my _SharedVar udf The blue window also changes to 100.But the recorder never catch it (probably for a reason related to the bug I guess? ) Edited March 7, 2016 by Guest Link to comment Share on other sites More sharing options...
JohnOne Posted March 5, 2016 Author Share Posted March 5, 2016 Still not proper getting it. If the cpu only does one thing at a time , which I think is established, then the program, no matter how it might want to cannot tell the cpu to do two things at once. I'm talking about 2 threads of user process here, each wanting to change value at an address, thread 1 says "change it now" and thread 2 says the same, to me the cpu processes the request of thread 1 and changes value, then it processes request of thread 2 and changes it again, because it can only do one thing at a time, right? Unless the simple request of thread to change value of lets say an int, is actually broken down by OS into a number of requests, like changing state of just one bit at that address, before switching to the broken down request of thread 2 and attempting to change state of 1 bit for it, and so on until all bits of memory block are changed. Is that is what is going on? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
trancexx Posted March 5, 2016 Share Posted March 5, 2016 18 hours ago, JohnOne said: Still not proper getting it. If the cpu only does one thing at a time , which I think is established, then the program, no matter how it might want to cannot tell the cpu to do two things at once. I'm talking about 2 threads of user process here, each wanting to change value at an address, thread 1 says "change it now" and thread 2 says the same, to me the cpu processes the request of thread 1 and changes value, then it processes request of thread 2 and changes it again, because it can only do one thing at a time, right? Unless the simple request of thread to change value of lets say an int, is actually broken down by OS into a number of requests, like changing state of just one bit at that address, before switching to the broken down request of thread 2 and attempting to change state of 1 bit for it, and so on until all bits of memory block are changed. Is that is what is going on? Imagine two functions running in different threads. Both have access to variable named x. First function: x = 1 MakeSureXisLessThan5() if x > 5 then DestroyTheWorld() DoNotDestroyTheWorld() Second one: Something() if SomethingElse() then x = 7 if x < 10 then HaveSexOfYourLife() x = 1 What if during running first thread two lines are executed, then execution is switched to second thread. In this thread also two lines of code is executed and function SomethingElse() returned "true". Then execution in this second thread is paused and switched to first thread. Now, even if in that first thread you called function MakeSureXisLessThan5() to be sure x has correct value when third line is executed the value of x will be 7 and the world will be destroyed. If in the other thread 4 lines of code have had been executed, the world would still be existing and you would feel much better because of possibly executed line 3. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
czardas Posted March 6, 2016 Share Posted March 6, 2016 (edited) What would happen if you ran that in reverse? Edited March 6, 2016 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JohnOne Posted March 6, 2016 Author Share Posted March 6, 2016 See, now I would not have considered that as a race condition, I would have thought that is what should happen, but if ran in a loop would that code crash it's process? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Bowmore Posted March 6, 2016 Share Posted March 6, 2016 I found this short Wikipedia article helped me understand some of what is being discussed in this thread. https://en.wikipedia.org/wiki/Lamport%27s_bakery_algorithm However it appears that what I thought of as a race condition previously is something else. I had thought that a race condition occurred when the part of the operating system responsible for allocating slices of time on the CPU was receiving so many request for a slice of time the the process of allocating time slices was consuming all or nearly all the available time slices on the CPU , Much like a Deninal Of Service web attack works. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
trancexx Posted March 6, 2016 Share Posted March 6, 2016 7 hours ago, JohnOne said: See, now I would not have considered that as a race condition, I would have thought that is what should happen, but if ran in a loop would that code crash it's process? It would destroy the world. Doesn't that count? Based on that simple model any kind of code can be written, even such that could crash the process. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted March 6, 2016 Author Share Posted March 6, 2016 It would be enough if you wanted to destro the world, but if your process crashed before it could, you'd be pretty pissed off. I'm still trying to connect the dots here. When the OS instructs the CPU to change the value of an int, does the CPU carry out that instruction in one go / cycle / or whatever it's called? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now