This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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.
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.