• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scheduling an interrupt on a borrowed thread

 
praveen kumaar
Ranch Hand
Posts: 242
4
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The authors of "Threads In Practice" have quoted:

If the task completes before the timeout, the cancellation task that interrupts the thread in which timedRun was called could go off after timedRun has returned to its caller


given the TimedRun code below-



Further, if the task is not responsive to interruption,timedRun will not return until the task finishes, which may be long after the desired timeout(or even not at all). A timed run service that doesn't return after the specified time is likely to be irritating to its callers.


can anyone explain what actually they meant to say?
 
praveen kumaar
Ranch Hand
Posts: 242
4
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i have posted a question about 7 hours ago but till now i have not get any solution.so i worked myself on this.

i found it in a sense(I don't know whether author is intending to mention the same or
not,thats why i am posting here in order to let me know whether am i correct or not ? )

the problem with the code seems like this-suppose the time at which executor thread interrupt the
taskthread may be at that time run method of "r" has not completed causing invalid termination of
taskthread (before successful execution) consequently giving the inconsistent results or another sitution is
when the taskthread is not responsive to interruption causing taskthread to run for a long time
resulting in breaking the policy of timedRun.

correct me if i am wrong.

reply will be appreciated.

thanks.

regards
praveen
 
Henry Wong
author
Marshal
Pie
Posts: 22096
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... I am not exactly sure why you felt that creating a new topic was preferred, than to simply following up ... regardless, I have merged your topics together. Hopefully, this will keep the discussion together in one place.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 22096
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
praveen kumaar wrote:
Further, if the task is not responsive to interruption,timedRun will not return until the task finishes, which may be long after the desired timeout(or even not at all). A timed run service that doesn't return after the specified time is likely to be irritating to its callers.


can anyone explain what actually they meant to say?


Well, as you may have noticed, communications between threads is mostly cooperative. This also includes interrupts. It is possible for a thread to be doing stuff that isn't interruptable. It is possible for a thread to not check the interrupt status. It is possible for a thread to not handle the case of being interrupted, and mess everything up. I believe the first few, which may cause the thread to go pass its desired timeout, is what the author was referring to.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic