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

Thread.currentthread method on multi cpu  RSS feed

 
tsrif tsal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on muliple cpu machine - surely there are > 1 currently running thread.
how does the method Thread.currentthread() work?
you would expect it to return a list of currently running threads.
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe it will be returning the Thread that your code is running on at the moment you call currentThread() method.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tsrif, why do you think there should always be >1 threads running on a multiprocessor system? There are of course some background threads running in the JVM which you have on every system but I think you're talking about the threads running your own code. And there are only the threads you would have on a single processor system which means usually just the main thread your code is automatically running in.

So your applications don't necessarily run multi-threaded just because they are running on a multiprocessor system. The main difference is that a multiprocessor system has the ability to run multiple threads really in parallel - in contrast to a single processor system which has to use some scheduler mechanisms for parallelizing threads. And perhaps on a multiprocessor systems you'll see more errors regarding the visibility of shared data because of caching effects etc. if your code isn't really thread-safe.

Marco
 
Henry Wong
author
Sheriff
Posts: 22849
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how does the method Thread.currentthread() work?
you would expect it to return a list of currently running threads


Yes, it is true. In a multicore / multiprocessor system it is possible to have more than one currently running thread.

But that is not the purpose of the method. The purpose of the method is to return the Thread object that is running the current code that calls the method -- and the purpose of that is to write thread specific code.

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