![]() |
[Q] How are we supposed to use threads in our robot code?
Hey, I'm a new programmer, and right now me and one of my friends are involved in porting our robot code to c++. One big thing that's been throwing me off however is c++'s apparent lack of threads. Whenever I google it I get suggestions to use the Boost library, which I have no idea how to use with WPILib. Results are even harder to find because of the clash of terminology (Google keeps confusing forum threads with code threads), so the end result is that I'm really not sure how (or if) I can thread the code.
I'm building off of the SimpleTemplate project, if you wanted to know. Thanks! |
Re: [Q] How are we supposed to use threads in our robot code?
Quote:
Use the Task class instead, that allows you to create additional threads using WPILib. |
Re: [Q] How are we supposed to use threads in our robot code?
Are you saying that I have to use boost and WPILib's task class? I looked on WPILib's task documentation page , and it doesn't look like I need to. Just looking for clarification.
Also, on the above page, it says the task::run takes the arguments of types FUNCPTR and int. just asking, the fcptr is just the function name without any arguments or parentheses, correct? Also the arguments are of type int, does that mean I can only pass integers? Sorry for bombarding you with questions but, like I said, I'm new to this and have no coders on the team experienced enough with c++ to help us. |
Re: [Q] How are we supposed to use threads in our robot code?
I would take a look at pthreads.
|
Re: [Q] How are we supposed to use threads in our robot code?
Quote:
Quote:
Quote:
I recommend searching these forums for more information, other people have asked the same questions. |
Re: [Q] How are we supposed to use threads in our robot code?
You will never need to use Boost or any external libraries for any multithreading in C++ for FRC, so save yourself some headaches and just WPILib because it works like a charm.
Here's some code that makes a separate thread to flip the state of a relay, which is spawned at TeleopInit, and killed off at DisabledInit. Code:
class Robot: public SimpleRobot{http://www.chiefdelphi.com/forums/sh...ad.php?t=82398 If you need explanation of anything in this post, just refer to that post^ |
Re: [Q] How are we supposed to use threads in our robot code?
My team produced a class this year which worked quite well and is quite extensible. All the source is on github. I also gave a pretty complete training discussion about how the class works and why in:
http://www.chiefdelphi.com/forums/sh...87#post1232587 If you have questions after reading that, feel free to contact me or post here. or there. Thanks, bob |
| All times are GMT -5. The time now is 12:51. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi