Log in

View Full Version : Questions on WPILib components thread usage


Varriount
28-01-2012, 15:36
Hello, my team has just started programming in java, and we've studied the documentation of WPILib, however some of us still have questions regarding thread safety and thread usage of WPILib's components.
What, if any, components of WPILib use threads? (Not including java's native thread library)
Does the VM on the cRio do any sort of automatic background threading or threading without the explicit usage of thread objects, in such a way that we would need to ensure the thread safety of our code?

Chiller
28-01-2012, 18:26
Yes, all screw holes are threaded.

Varriount
29-01-2012, 12:29
Um, excuse me? Chiller, could you clarify?

krieck
29-01-2012, 15:00
Digging through the WPILIBJ source code, I can see a couple of threads created, but only for minor asynchronous communication. Preferences, for instance, are saved and retrieved in a separate thread. Some of the networktable methods manage connections in separate threads.

The actual robot code seems to run entirely in a single thread.

Thread-safety is a good topic to discuss and an important discipline to remember, but I think that it will not be an issue in your robot code.

Varriount
29-01-2012, 15:20
Thanks for the information krieck. It's one less thing for our team to worry about. What about the command system? One would think that to run commands synchronously, they would be run in a seperate thread?

Sunstroke
29-01-2012, 16:12
Thanks for the information krieck. It's one less thing for our team to worry about. What about the command system? One would think that to run commands synchronously, they would be run in a seperate thread?

They are not, instead commands are just run in order in a single thread. Because of the iterative nature of commands though, this makes the run concurrently.

However, there is a downside because if one of your commands calls sleep or whatnot in its execute method, then all the other commands will have to wait for yours to finish before they do anything.

Ether
29-01-2012, 16:45
Thanks for the information krieck. It's one less thing for our team to worry about. What about the command system? One would think that to run commands synchronously, they would be run in a seperate thread?

Did you mean concurrently?

Varriount
29-01-2012, 16:47
Did you mean concurrently?
Ah, yes, I did mean concurrently, sorry.