Giter Site home page Giter Site logo

Comments (10)

PeterMitrano avatar PeterMitrano commented on June 23, 2024

It looks right to me. It's the same way we do it in non-sim

from allwpilib.

ThadHouse avatar ThadHouse commented on June 23, 2024

That is the right way to do it. We usually use a timeout of 0 anyway, which forces a wait for GetData to get called and ran. But I think I tested it last summer and the timeouts work as well.

from allwpilib.

JLLeitschuh avatar JLLeitschuh commented on June 23, 2024

Regardless of that, you are totally throwing away the interrupted flag.

It should be:

    public void waitForData(long timeout) {
        synchronized (m_dataSem) {
            try {
                m_dataSem.wait(timeout);
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
        }
    }

from allwpilib.

PeterMitrano avatar PeterMitrano commented on June 23, 2024

That certainly looks better. What does interrupting ourself do? And when might this situation occur?

from allwpilib.

JLLeitschuh avatar JLLeitschuh commented on June 23, 2024

InterruptedException is a pain in the *** and not many people know how to handle it correctly.
http://www.yegor256.com/2015/10/20/interrupted-exception.html
http://www.ibm.com/developerworks/library/j-jtp05236/

from allwpilib.

PeterMitrano avatar PeterMitrano commented on June 23, 2024

Ok. So since wait takes a long time we should be calling interrupt. But then we want to go back and continue the wait next time around, so what @JLLeitschuh suggested seems appropriate.

from allwpilib.

JLLeitschuh avatar JLLeitschuh commented on June 23, 2024

@PeterMitrano catch is only called if the current thread is interrupted, ie. the the exception has been thrown.
That bit of code will normally never run.

from allwpilib.

PeterMitrano avatar PeterMitrano commented on June 23, 2024

Yes, I'm aware. I'm just thinking through what would happen if an exception was thrown. I'll make a PR for that one line (in both places. java, and sim java).

from allwpilib.

PeterMitrano avatar PeterMitrano commented on June 23, 2024

Turns out this same thing exists in a few other places. Should I change those too? Like Preferences.java, CameraServer.java...

from allwpilib.

JLLeitschuh avatar JLLeitschuh commented on June 23, 2024

I'm hitting them as I do the checkstyle refactor

from allwpilib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.