United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6269146 : Cancelled FutureTask's interrupt bit not always set

Details
Type:
Bug
Submit Date:
2005-05-12
Status:
Resolved
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2005-09-04
Component:
core-libs
OS:
generic
Sub-Component:
java.util.concurrent
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports

Sub Tasks

Description
Doug Lea writes:

"As kindly pointed out by Tom May (Joe's ex-colleague), there
was a window in FutureTask, where a task that was not cancelled
soon enough to cause it not to be started still didn't set
that task's interrupt status (if mayInterrupt true), as it should
have according to spec."
###@###.### 2005-05-12 00:52:22 GMT

                                    

Comments
EVALUATION

Part of jsr166x project
###@###.### 2005-05-12 01:05:46 GMT
                                     
2005-05-12
SUGGESTED FIX

--- FutureTask.java	2 May 2005 18:38:53 -0000	1.35
+++ FutureTask.java	12 May 2005 00:12:38 -0000	1.37
@@ -265,7 +265,10 @@
                 return;
             try {
                 runner = Thread.currentThread();
-                innerSet(callable.call());
+                if (getState() == RUNNING) // recheck after setting thread
+                    innerSet(callable.call());
+                else
+                    releaseShared(0); // cancel
             } catch (Throwable ex) {
                 innerSetException(ex);
             }
@@ -276,7 +279,8 @@
                 return false;
             try {
                 runner = Thread.currentThread();
-                callable.call(); // don't set result
+                if (getState() == RUNNING)
+                    callable.call(); // don't set result
                 runner = null;
                 return compareAndSetState(RUNNING, 0);
             } catch (Throwable ex) {

###@###.### 2005-05-12 01:05:47 GMT
                                     
2005-05-12



Hardware and Software, Engineered to Work Together