Demonstrate the basic use of threads.
Demonstrate the basic use of threads. See also os/periodicthread/periodicthread.cpp
#include <cstdio>
constexpr double thread1_delay = 1.0;
constexpr double thread2_delay = 0.5;
constexpr double main_delay = 3.0;
class Thread1 : public Thread
{
public:
bool threadInit() override
{
printf("Starting thread1\n");
return true;
}
void run() override
{
while (!isStopping()) {
printf("Hello, from thread1\n");
}
}
void threadRelease() override
{
printf("Goodbye from thread1\n");
}
};
class Thread2 : public Thread
{
public:
bool threadInit() override
{
printf("Starting thread2\n");
return true;
}
void run() override
{
while (!isStopping()) {
printf("Hello from thread2\n");
}
}
void threadRelease() override
{
printf("Goodbye from thread2\n");
}
};
int main()
{
Thread1 t1;
Thread2 t2;
printf("Starting threads...\n");
t1.start();
t2.start();
printf("started\n");
printf("stopping threads...\n");
t1.stop();
t2.stop();
printf("stopped\n");
return 0;
}
Utilities for manipulating the YARP network, including initialization and shutdown.
An abstraction for a thread of execution.
void delay(double seconds)
Wait for a certain number of seconds.
The main, catch-all namespace for YARP.