cpplint: lint things a bit
https://raw.githubusercontent.com/cpplint/cpplint/HEAD/cpplint.py Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
78660fb70e
commit
01101c84a0
5 changed files with 64 additions and 61 deletions
68
worker.h
68
worker.h
|
|
@ -1,9 +1,11 @@
|
|||
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
|
||||
|
||||
// https://en.cppreference.com/w/cpp/thread/thread
|
||||
// https://en.cppreference.com/w/cpp/thread/mutex
|
||||
// https://en.cppreference.com/w/cpp/thread/condition_variable
|
||||
|
||||
#ifndef WORKER_H_INCLUDED_
|
||||
#define WORKER_H_INCLUDED_
|
||||
#ifndef WORKER_H_
|
||||
#define WORKER_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
|
@ -11,40 +13,42 @@
|
|||
#include <mutex>
|
||||
|
||||
namespace Dang {
|
||||
class Worker {
|
||||
public:
|
||||
Worker() {
|
||||
this->ready = false;
|
||||
//init();
|
||||
};
|
||||
|
||||
void run() {
|
||||
std::unique_lock<std::mutex> lock(this->mtx);
|
||||
this->cv.wait(lock, [this] { return this->ready; }); // Wait until 'ready' is set to true
|
||||
std::cout << "Daemon process woke up!" << std::endl;
|
||||
};
|
||||
|
||||
int work() {
|
||||
std::thread daemon([this] {this->run();});
|
||||
class Worker {
|
||||
public:
|
||||
Worker() {
|
||||
this->ready = false;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mtx);
|
||||
this->ready = true;
|
||||
}
|
||||
this->cv.notify_one();
|
||||
void run() {
|
||||
std::unique_lock<std::mutex> lock(this->mtx);
|
||||
// Wait until 'ready' is set to true
|
||||
this->cv.wait(lock, [this] { return this->ready; });
|
||||
std::cout << "Daemon process woke up!" << std::endl;
|
||||
}
|
||||
|
||||
daemon.join();
|
||||
return 0;
|
||||
};
|
||||
int work() {
|
||||
std::thread daemon([this] {this->run();});
|
||||
|
||||
private:
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
bool ready;
|
||||
};
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mtx);
|
||||
this->ready = true;
|
||||
}
|
||||
this->cv.notify_one();
|
||||
|
||||
#endif // WORKER_H_INCLUDED_
|
||||
daemon.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
bool ready;
|
||||
};
|
||||
|
||||
} // namespace Dang
|
||||
|
||||
#endif // WORKER_H_
|
||||
|
||||
// vim:set sts=2 sw=2 et:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue