Did I misunderstand the concept of threads?

L

Lars Uffmann

Hey everyone!

In a previous post, I was asking about thread programming in C++ and was
pointed to the boost libraries. However, now I am reading in the
boost.thread documentation at
http://www.boost.org/doc/html/thread.html#thread.glossary / Table 15.26
for Thread State that "Running" means: "Currently executing on a
processor. Zero or more threads may be running at any time, with a
maximum equal to the number of processors."

So does that mean multithreading is only intended for multi-processor
environments? What I was thinking about was actually more like... handle
network data in a procedure (which I thought would be a thread) that is
permanently listening to incoming packets, while the rest of my
application (GUI) is still reacting to user input.

I have used a "thread" implementation of widestudio for this
successfully, so I didn't really have the idea this could be the wrong
approach.

What would be the correct approach to run several processes in parallel
on a single-core system (or regardless of the amount of cores)?

TIA,

Lars
 
M

Matthias Buelow

Lars said:
So does that mean multithreading is only intended for multi-processor
environments?

It just says that "Running" means the thread is currently being executed
on a CPU, not that the thread is runnable in general (as opposed to
waiting, sleeping, etc.) Obviously, you can't have more threads being
executed simultaneously than you have CPUs (cores). It's a bit silly
this trivial fact is mentioned explicitly.
 
P

Pete Becker

In a previous post, I was asking about thread programming in C++ and
was pointed to the boost libraries. However, now I am reading in the
boost.thread documentation at
http://www.boost.org/doc/html/thread.html#thread.glossary / Table 15.26
for Thread State that "Running" means: "Currently executing on a
processor. Zero or more threads may be running at any time, with a
maximum equal to the number of processors."

Yup. That's simply a physical fact: with only one processor, only one
thread of execution can run at a time.
So does that mean multithreading is only intended for multi-processor
environments?

No. On single-processor systems, the threading mechanism switches the
processor from one thread to another, giving each running thread a
chunk of run time. In fact, the same thing happens whenever there are
more threads than there are processors.
 
L

Lars Uffmann

Thank you Matthias & Pete for clearing that up :) I'm reading my way
through the boost.thread documentation as I'm writing this...

Best Regards,

Lars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top