Hi all,
I discovered a strange behaviour of Sleep actor. The actor documentation says: "If fire() is called multiple times in one iteration, sleep is only called the first time". But, analizing the actor code, I note that the variable _wasSleepCalledInFireYet is never set to true in the fire() method. In this way, if the fire() method is called n-times in one iteration, also the sleep is called n-times.

This problem will be resolved by adding a new code line in the fire() method. In this way, it is possible to set the variable _wasSleepCalledInFireYet to true.


public void fire() throws IllegalActionException {
        int inputWidth = input.getWidth();
        Token[] inputs = new Token[inputWidth];

        for (int i = 0; i < inputWidth; i++) {
            if (input.hasToken(i)) {
                inputs[i] = input.get(i);
            }
        }

        if (!_wasSleepCalledInFireYet) {
            try {
                _wasSleepCalledInFireYet = true;
                long sleepTimeValue = ((LongToken) sleepTime.getToken())
                    .longValue();

                if (_debugging) {
                    _debug(getName() + ": Wait for " + sleepTimeValue
                            + " milliseconds.");
                }

                Thread.sleep(sleepTimeValue);
            } catch (InterruptedException e) {
                // Ignore...
            }
        }

        int outputWidth = output.getWidth();

        for (int i = 0; i < inputWidth; i++) {
            if (inputs[i] != null) {
                if (i < outputWidth) {
                    output.send(i, inputs[i]);
                }
            }
        }
    }


Thanks,
Adriana

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to