Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic thread question  RSS feed

 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As I understand, if we have a single processor CPU then we can program to have multiple threads being executed by
the processor. What I want to know is whether reverse is also possible, ie a single thread being managed by multiple processors?

Manish
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manish ghildiyal wrote:As I understand, if we have a single processor CPU then we can program to have multiple threads being executed by
the processor. What I want to know is whether reverse is also possible, ie a single thread being managed by multiple processors?

The fact is: Dunno - and I suspect it'll depend very much on the architecture of the machine in question.

From what I understand, the JVM uses the threading architecture supplied by the OS, so the answer may well be different for different OS's, chipsets, CPUs and any number of other things beyond my ken.

My question: Why are you worried about this?

Winston
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winsotn, thanks for reply.
Actually I wanted to know how multi threading works from CPU point of view...so was just curious.

Manish
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:
The fact is: Dunno - and I suspect it'll depend very much on the architecture of the machine in question.

From what I understand, the JVM uses the threading architecture supplied by the OS, so the answer may well be different for different OS's, chipsets, CPUs and any number of other things beyond my ken.


Correct. I believe all current JVMs do delegate the scheduling duties to the underlying OS -- so, this is not a Java question, but more of a generic threading question.

manish ghildiyal wrote:
Actually I wanted to know how multi threading works from CPU point of view...so was just curious.


For the OSes that I recently worked with (in the last few years), Windows, Solaris, various Linux implementations, and on the Azul appliance, they will run threads from the same application across different cores. This means that for multicore and multiprocessor machines, the OS can run the runnable threads in parallel (using more than one core on the machine).

For the case of multiple threads on a single core machine, the machine will time-slice the runnable threads on the core. Also, for the case of when there are more runnable threads than cores, the OS will time-slice the threads across all the cores.

For the last case (for this topic), where there is only one thread on lots of cores, the OS should basically use only one core. Unfortunately, there is really no good way of using more than one processor core with a single threaded application.

Henry
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for such a detailed reply Henry.

Manish
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manish ghildiyal wrote:Thanks for such a detailed reply Henry.

Just to add a little background to this:
Windows was designed originally as a standalone OS, whereas Unix was designed from the ground up to be multitasking. Indeed, it was benchmarked and proved on 286 processors, which were never designed for multitasking. Thus, threads (and actually, different categories of thread, such as LWPs) have always been part of the Unix/Linux model; not so with Windows.

Java is a child of the time when all these systems started to merge and provide multitasking (or threading) as standard.

What's slightly more difficult to convey is just how fast modern processors are. Even a single-core processor can be made to "appear" as though it's multi-tasking with a decent time-slicing algorithm, because if it wasn't actually performing several tasks (in series) it would be spinning its wheels.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!