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

interrupt()and priorities  RSS feed

 
Henry H
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will a thread be able to interrupt another thread that has higher priority than itself?
Thanks
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Will a thread be able to interrupt another thread that has higher priority than itself?

Interesting question.
Thread A - Lower priority thread
Thread B - Higher priority thread
This means that the thread A is in a running state and is about to interrupt a thread of higher priority. But if the thread A is running it that means that the thread B is sleeping . It cannot be in a Runnable state as it would be running in this case, as it has higher priority. Thus B wakes up to handel its interrupt exception.
Can you think what happens if thread B is waiting ???
Hope things are clear.

------------------
Regds.
Rahul P. Mahindrakar
 
mohit joshi
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My answer would be yes. If thread B is sleeping or waiting then
It would throw InterruptedException. If it is blocking for I/O
then the Interrupted Exception may not be thrown,which is the case with even same priority threads.
If B is running, then A is not. However B may yield and let A run and if A calls interrupt(), then it should set the Interrupted flag of B, thus interrupting B.
I am confused over 2 things. How does Green thread Scheduler work
on windows platform. Does it allows only High priority threads to run and Low priority threads are not run at all, or does it follow round-robin scheduling.I suppose the native threads on windows( which are the threads supplied by OS??)do follow round-robin scheduling.Atleast the Window API threads do.
Secondly, can a thread Create threads which are Higher Priority then itself?My answer would be yes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!