473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

is threading useful with a single CPU?

Just trying to understand the basics here. If the OS has just one CPU, what
advantage is there in threading? thanks
Jul 2 '06 #1
6 1403
Fred Exley <fe*******@msn.comwrote:
Just trying to understand the basics here. If the OS has just one CPU, what
advantage is there in threading? thanks
Consider a situation where you want to get the contents of 10 different
web pages. Making each request in series will take a lot longer than
making the requests in parallel using multiple threads. Using
asynchronous requests would be a solution in this particular case
(although that uses multiple threads behind the scenes amongst other
things) but it's a good example of the situation where threading is
useful even on a single-core-single-CPU system: bottlenecks aren't
always (or even usually) in the processor.

Another simple example is keeping a UI responsive - by performing long-
running tasks in another thread, the thread associated with the UI can
be available for updating the screen, responding to user actions etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 2 '06 #2
Fred Exley wrote:
Just trying to understand the basics here. If the OS has just one CPU,
what
advantage is there in threading? thanks
Hi Fred,

Threading is everywhere. It's not just a concept that's useful on two CPUs.

Take two applications, AppA and AppB. If you start these on your computer,
how can you switch between them? How can AppA calculate a list of prime
numbers, while AppB is calculating Pi to a million decimal places?

The answer is threading: Whenever you start a process, that process will
initially begin in one thread, and can then spawn more and more threads.
Going back to AppA and AppB, when you launch these two applications, AppA
will start it's thread and AppB will start it's thread. AppA's thread
contains code to calculate prime numbers and AppB's thread contains code to
calculate Pi. These two processes appear to run simultaneously, because
the operating system is scheduling the execution of each thread, and
allowing the thread to run.

Taking a much larger example, e.g. Microsoft Word, and Microsoft Visual
Studio. When you launch these applications, you can switch between them,
you can start VS compiling and you can write a document in Word. These
applications also create multiple threads, to do various tasks.

Multiple threads within a single process are used to execute code
simultaneously (or what appears to be simultaneously).

The following article will probably be of better use to you:

http://en.wikipedia.org/wiki/Thread_...ter_science%29

--
Hope this helps,
Tom Spink
Jul 2 '06 #3

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
Fred Exley <fe*******@msn.comwrote:
>Just trying to understand the basics here. If the OS has just one CPU,
what
advantage is there in threading? thanks

Consider a situation where you want to get the contents of 10 different
web pages. Making each request in series will take a lot longer than
making the requests in parallel using multiple threads. Using
asynchronous requests would be a solution in this particular case
(although that uses multiple threads behind the scenes amongst other
things) but it's a good example of the situation where threading is
useful even on a single-core-single-CPU system: bottlenecks aren't
always (or even usually) in the processor.

Another simple example is keeping a UI responsive - by performing long-
running tasks in another thread, the thread associated with the UI can
be available for updating the screen, responding to user actions etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

" ...bottlenecks aren't always (or even usually) in the processor.", etc.

Ahh, got it! Thanks much, Jon, and Tom too.
Jul 2 '06 #4
"Fred Exley" <fe*******@msn.comwrote in message
news:12*************@corp.supernews.com...
" ...bottlenecks aren't always (or even usually) in the processor.", etc.

Ahh, got it! Thanks much, Jon, and Tom too.
You are correct though in that threading is not always an advantage. If 2
threads start at the same time which use full processor power then the
average time to get a result will be longer. Eg if both tasks would have
taken 5 seconds each then you would get one result at 5 seconds and another
at 10 so a 7.5 sec average. If you run them together you'll get both results
at 10 seconds.

Michael
Jul 3 '06 #5
Michael I would say that you would get them in 10.5+ seconds (remember the
overhead for context switching) :)

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
"Michael C" <no****@nospam.comwrote in message
news:OW**************@TK2MSFTNGP02.phx.gbl...
"Fred Exley" <fe*******@msn.comwrote in message
news:12*************@corp.supernews.com...
>" ...bottlenecks aren't always (or even usually) in the processor.", etc.

Ahh, got it! Thanks much, Jon, and Tom too.

You are correct though in that threading is not always an advantage. If 2
threads start at the same time which use full processor power then the
average time to get a result will be longer. Eg if both tasks would have
taken 5 seconds each then you would get one result at 5 seconds and
another at 10 so a 7.5 sec average. If you run them together you'll get
both results at 10 seconds.

Michael

Jul 3 '06 #6

"Greg Young" <dr*******************@hotmail.comwrote in message
news:O7**************@TK2MSFTNGP05.phx.gbl...
Michael I would say that you would get them in 10.5+ seconds (remember the
overhead for context switching) :)

Cheers,

Greg Young
MVP - C#
In my old mainframe days there was such a thing known as thrashing, where
the overhead of switching tasks exceeded the timeslices of the actual tasks.
Jul 3 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
12
by: Gurpreet Sachdeva | last post by:
I have written a code to figure out the difference in excecution time of a func before and after using threading... #!/usr/bin/env python import threading import time loops =
13
by: Varun | last post by:
Hi Friends, Department of Information Technology, Madras Institute of Technology, Anna University, India is conducting a technical symposium, Samhita. As a part of samhita, an Online Programming...
2
by: AtherMurtuzapurwala | last post by:
Hi All, Client/Server Program using Sockets... Server sends request in form of CSV format in NetworkStream... So I want to read this using threading because it is in very large volume so...
0
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
4
by: Steven | last post by:
I am taking an "advanced" VB.Net course via web at a state university toward an information science degree. This is my second VB class and I am kind of disappointed in it. This week we covered...
14
by: Akihiro KAYAMA | last post by:
Hi all. I found cooperative multi-threading(only one thread runs at once, explicit thread switching) is useful for writing some simulators. With it, I'm able to be free from annoying mutual...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.