Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How Threads run at same time ?

 
Monoj Roy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a single CPU then how two thread get the single CPU pulse at same time ..?I mean when I just start two thread how they start simultaneously
I am thinking in point of the CPU .How the same clock pulse share by the two thread ?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are presumably happy with the way that modern single-CPU computers give the illusion of doing more than one thing at once, in multi-processing. Your word processor, Web browser and e-mail all appear to be running at once, in separate processes.

Threads achieve the illusion of simultaneous execution by very similar means to processes. The efforts of the CPU(s) are switched between threads and processes, rapidly, so that all get some time. At any one time, only one thread in one process is actually running, but the switching is fast enough that you don't notice.

As a Java programmer, you shouldn't worry too much about the low-level stuff that makes threads happen. They just do, and 90% of the time, that's enough to know.
[ October 11, 2007: Message edited by: Peter Chase ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll repeat a favorite company legend here ... My company got into computing in a big way from the late 50s on. Our Chief Scientist was on the COBOL committee but decided it was moving too slowly and wrote our own language that we used until the Y2K panic. We were so far out on the bleeding edge we modified hardware and operating systems like Google does today.

Somebody wired a speaker across one of the tubes in the CPU so it buzzed when things were running. They could play Christmas carols by coding loops of different operations ... 2+2 is a D flat, 4*3 is an F and so on.

One day all the top guys are standing around and observed the speaker goes silent for a few seconds while punching cards or reading 3/4 inch tape. Somebody says, "Hey, maybe we could start two programs, one could run while the other is waiting for IO." They all listen to the speaker go on and off a few times and say ... "Naahhhh"

Probably not even a totally true story, but it is one way threads work. The system runs a few instructions from one thread, then a few from another, then another. If the threads are all busy doing math in the CPU, these interruptions are A Bad Thing. The system has to do a lot of work to switch from one thread to another and that just adds to the total time for all work. But if the threads sometimes wait for IO or some other slow or blocking operation, then running another thread during that time is a big win.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See http://en.wikipedia.org/wiki/Computer_multitasking
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic