Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DriverStation.waitForData This doesn't seem right #12

Closed
JLLeitschuh opened this issue May 12, 2016 · 10 comments
Closed

DriverStation.waitForData This doesn't seem right #12

JLLeitschuh opened this issue May 12, 2016 · 10 comments
Labels
type: bug Something isn't working.

Comments

@JLLeitschuh
Copy link
Member

JLLeitschuh commented May 12, 2016

I'm not 100% sure what the original author intended for this method to be but I'm fairly confident that it doesn't do what it's documented to do.

https://github.com/wpilibsuite/allwpilib/blob/master/wpilibj/src/sim/java/edu/wpi/first/wpilibj/DriverStation.java#L135

Also, its missing the Thread.curentThread().interrupt() to reset the interrupt flag.

@JLLeitschuh JLLeitschuh changed the title DriverStation. waitForData DriverStation.waitForData This doesn't seem right May 12, 2016
@JLLeitschuh JLLeitschuh added the type: bug Something isn't working. label May 12, 2016
@PeterMitrano
Copy link
Contributor

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

@ThadHouse
Copy link
Member

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.

@JLLeitschuh
Copy link
Member Author

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();
            }
        }
    }

@PeterMitrano
Copy link
Contributor

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

@JLLeitschuh
Copy link
Member Author

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/

@PeterMitrano
Copy link
Contributor

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.

@JLLeitschuh
Copy link
Member Author

@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.

@PeterMitrano
Copy link
Contributor

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).

@PeterMitrano
Copy link
Contributor

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

@JLLeitschuh
Copy link
Member Author

I'm hitting them as I do the checkstyle refactor

PeterJohnson pushed a commit that referenced this issue Apr 28, 2018
Makes the jar much easier to find when attempting to combine.
PeterJohnson referenced this issue in PeterJohnson/allwpilib Jul 25, 2020
Co-authored-by: Zhiquan Yeo <zyeo8@bloomberg.net>
pjbuterbaugh pushed a commit to pjbuterbaugh/allwpilib that referenced this issue Jun 15, 2023
* FRC Update Suite

* index fix for updatesuite
pjreiniger referenced this issue in bzlmodRio/allwpilib Jun 21, 2023
* Enable CI for more toolchains

* lint
pjbuterbaugh pushed a commit to pjbuterbaugh/allwpilib that referenced this issue Jul 24, 2023
* FRC Update Suite

* index fix for updatesuite
r4stered pushed a commit to r4stered/allwpilib that referenced this issue Jan 1, 2024
Added cpp version of sysid routine commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

3 participants