Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How threads are created in multi core CPU ?  RSS feed

 
Muztaba Hasanat
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have couple of questions regarding multi threading.

1. Suppose that I have a 6 core processor. In that machine I've created 6 threads. Are those 6 threads execute separately under 6 core ? I mean, 6 cores will run 6 threads ?

2. If the program is running on a single core machine then how come the concurrency achieve?



3.
If this code would run in a single core machine with multiple threads then how those threads behave ?

And also consider this code segment -



4. What will happen when this two methods will execute in two threads on a single core machine ? Does those threads execute sequentially ? Like after executing first thread for a while then pause then resume the second thread. Then again second thread pause and resume first thread. Is this the way it works ?

Thank you.
 
Henry Wong
author
Sheriff
Posts: 22846
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muztaba Hasanat wrote:
1. Suppose that I have a 6 core processor. In that machine I've created 6 threads. Are those 6 threads execute separately under 6 core ? I mean, 6 cores will run 6 threads ?


The answer depends on the implementation. Most moderns JVM will forward the scheduling of threads to the Operating System. And most OS schedulers are smart enough to use all the cores. So yes, it is possible to have 6 running threads on the 6 cores.

Muztaba Hasanat wrote:
2. If the program is running on a single core machine then how come the concurrency achieve?


Most OS schedulers will timeslice the runnable threads. Giving each a turn to be running. This is, of course, affected by their priority.

Also, the timeslicing is generally fine grain enough, that most people won't know that the threads are taking turns, and not truly running in parallel. Although, there are those who claim that they can tell the difference...

Henry
 
Muztaba Hasanat
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Muztaba Hasanat wrote:
1. Suppose that I have a 6 core processor. In that machine I've created 6 threads. Are those 6 threads execute separately under 6 core ? I mean, 6 cores will run 6 threads ?


The answer depends on the implementation. Most moderns JVM will forward the scheduling of threads to the Operating System. And most OS schedulers are smart enough to use all the cores. So yes, it is possible to have 6 running threads on the 6 cores.

Muztaba Hasanat wrote:
2. If the program is running on a single core machine then how come the concurrency achieve?


Most OS schedulers will timeslice the runnable threads. Giving each a turn to be running. This is, of course, affected by their priority.

Also, the timeslicing is generally fine grain enough, that most people won't know that the threads are taking turns, and not truly running in parallel. Although, there are those who claim that they can tell the difference...

Henry


Thanks for the reply.

Sorry I did not understand that your are still giving reply. Sorry for interruption.
 
Henry Wong
author
Sheriff
Posts: 22846
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muztaba Hasanat wrote:
Sorry I did not understand that your are still giving reply. Sorry for interruption.


Not sure what you are saying. Can you elaborate?

Henry
 
Muztaba Hasanat
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Muztaba Hasanat wrote:
Sorry I did not understand that your are still giving reply. Sorry for interruption.


Not sure what you are saying. Can you elaborate?

Henry
when you gave the first question answer I replied. But after posting my comment I noticed that you gave second question answer of mine. That is why, I thought you were not still finished.
 
Henry Wong
author
Sheriff
Posts: 22846
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muztaba Hasanat wrote:when you gave the first question answer I replied. But after posting my comment I noticed that you gave second question answer of mine. That is why, I thought you were not still finished.


Oh, that's what you meant. Okay, so everything good now? All doubts cleared? ...

Henry
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!