threads.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 47 行
CPP
47 行
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
#include <stdio.h>
#include <yarp/os/Thread.h>
#include <yarp/os/Time.h>
using namespace yarp::os;
class Thread1 : public Thread {
public:
virtual void run() {
while (!isStopping()) {
printf("Hello, from thread1\n");
Time::delay(1);
}
}
};
class Thread2 : public Thread {
public:
virtual void run() {
Time::delay(0.5);
while (!isStopping()) {
printf("Hello from thread2\n");
Time::delay(1);
}
}
};
int main() {
Thread1 t1;
Thread2 t2;
printf("Starting threads...\n");
t1.start();
t2.start();
printf("started\n");
Time::delay(3);
printf("stopping threads...\n");
t1.stop();
t2.stop();
printf("stopped\n");
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?