#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    75
    Rep Power
    2

    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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,477
    Rep Power
    1752
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    75
    Rep Power
    2
    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?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,477
    Rep Power
    1752
    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

IMN logo majestic logo threadwatch logo seochat tools logo