harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jarek Gawor (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-5933) FutureTask.cancel() might not actaully cancel the task
Date Tue, 05 Aug 2008 16:34:44 GMT
FutureTask.cancel() might not actaully cancel the task

                 Key: HARMONY-5933
                 URL: https://issues.apache.org/jira/browse/HARMONY-5933
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
    Affects Versions: 5.0M6
            Reporter: Jarek Gawor

In some circumstances java.util.concurrent.FutureTask.cancel() might not actaully cancel the
task. The problem is in innerCancel() method:

1.        boolean innerCancel(boolean mayInterruptIfRunning) {
2.            int s = getState();
3.            if (ranOrCancelled(s) || !compareAndSetState(s, CANCELLED))
4.                return false;
5.            <cancel logic>

The issue is that the state (s) can change between line 2 and 3 and so compareAndSetState(s,
CANCELLED) will return false and the cancel logic will not be performed (cancel() will return
false but that task is not complete and it will continue to execute). This problem is more
evident with periodic tasks where the state keep changing between 0 -> RUNNING, and RUNNING
-> 0 (see innerRunAndReset()).

Looks like FutureTask implementation in Sun's JDK avoids this problem by adding a for (;;)
loop around line 2 and 3:

for (;;) {
   int s = getState();
   if (ranOrCancelled(s)) {
     return false;
   if (compareAndSetState(s, CANCELLED)) {
<cancel logic>

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message