Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chrono>
- #include <thread>
- #include <functional>
- void call(int numero) {
- std::cout << numero << std::endl;
- return;
- }
- struct call_info{
- std::function<void(void)> func;
- };
- class b_timers {
- public:
- void start_timer() {
- std::cout << "Chamou" << std::endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(_milisegundos));
- if(_active & 1) {
- call_info& info = _myVec[0];
- info.func();
- }
- }
- void setProp(int milisegundos, std::function<void(void)> rnd) {
- call_info info;
- info.func = rnd;
- _myVec.push_back(info);
- _active = true;
- _milisegundos = milisegundos;
- }
- void setActive(bool set) {
- _active = set;
- }
- private:
- bool _active;
- int _milisegundos;
- std::vector<call_info> _myVec;
- };
- void mt_timer(b_timers Timer) {
- Timer.start_timer();
- return;
- }
- int main() {
- std::cout << "Inicio" << std::endl;
- std::function<void(void)> rnd = std::bind(call, 5);
- b_timers Timerx;
- Timerx.setProp(2000,rnd);
- std::thread thread_timer(mt_timer,Timerx);
- thread_timer.detach();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement