Jump to content

How computers work


Recommended Posts

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 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

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. :muttley:

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)

userbar.png

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Ha Ha, good one Jabbers. :thumbsup:

Don't you just love logic puzzles. :D

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)

userbar.png

Link to comment
Share on other sites

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

  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

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 by Guest
Link to comment
Share on other sites

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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...