|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Tasks in C++
You resurrected an old thread from 2013. Anyway, take a look at our code here. It works fine for us using WPILib's built in task setup (which I think is really just a wrapper for a pthread).
https://github.com/team2053tigertron.../src/Robot.cpp |
|
#2
|
|||
|
|||
|
Re: Tasks in C++
Task is a VXWorks API wrapper around pthreads. Any reason not to use pthreads directly?
Take a look at ::std::thread. It works well, and is much more cross platform. We use it exclusively. |
|
#3
|
||||
|
||||
|
Re: Tasks in C++
Quote:
TIA, Mike |
|
#4
|
|||
|
|||
|
Re: Tasks in C++
Quote:
Code:
-- snip --
::frc971::wpilib::GyroSender gyro_sender;
::std::thread gyro_thread(::std::ref(gyro_sender));
// Main loop here
// Now cleanup
gyro_sender.Quit();
gyro_thread.join();
-- snip --
// Handles reading the gyro over SPI and sending out angles on a queue.
//
// This is designed to be passed into ::std::thread's constructor so it will run
// as a separate thread.
class GyroSender {
public:
GyroSender();
// For ::std::thread to call.
//
// Initializes the gyro and then loops until Quit() is called taking readings.
void operator()();
void Quit() { run_ = false; }
private:
// Readings per second.
static const int kReadingRate = 200;
GyroInterface gyro_;
::std::atomic<bool> run_{true};
};
|
|
#5
|
||||
|
||||
|
Re: Tasks in C++
Quote:
Mike |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|