October 2nd, 2013, 09:56 AM
-
Simulating using threads
I saw some questions where processes like formation of molecules, battles etc. are simulated using threads on a compuer.
For eg:- If we want to make a molecule say H2O then we use on thread for hydrogen and other thread for oxygen.
I am unable to understand why we are doing this? How can threads correctly simulate the behaviour of water formation?
Since on a computer only one process can run at a single time and in the case of water, several atoms wil simultaneously react the simulation will obviously be wrong.
October 3rd, 2013, 07:14 AM
-
In the far, far distant past only one process could be active at a time - and this is still true, but we now have multi-threaded cores and mutli-cored CPUs. Thus we can have true multi-tasking and multi-processing; not just the illusion granted by 'clever' Operating Systems.
What you'd probably have is a parent process, spawning a child process for each element (or maybe each atom), with the child talking to the parent which arbitrates and collates the info, passing back needed information to any/all child process.
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
October 3rd, 2013, 07:28 AM
-
What I'm doing in my program is that I'm creating several threads and each thread performs some task. In case of simulating a battle one thread could kill another thread.
So if I have an Intel i5 processor then I believe it allows a maximum of four processes running at once, right? Still you could only have four things running at once and I'm simulating around 20-30 battles. It won't work, right?
Also to ensure, does my operating system actually run parallel processes?
October 3rd, 2013, 12:30 PM
-
That will depend on the actual OS.
I suspect you will have to do what most OSs do - fake it! You might also like to look up 'three body problem'
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc