-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeadLineTimer.cpp
More file actions
38 lines (32 loc) · 1.06 KB
/
deadLineTimer.cpp
File metadata and controls
38 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Motivation is to be able check if deadline timer works well with blocking calls
// Conclusion deadlinetimer will not work if the io_service is blocked in some other task
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/bind.hpp>
using namespace boost::asio;
using namespace std;
io_service io;
void callback(const boost::system::error_code& err) {
if (err == boost::asio::error::operation_aborted) {
std::cout<<"Timer cancelled: " << err.message()<<std::endl;
return;
} else if (err) {
std::cout<<"Timer error: " << err.message() << std::endl;
return;
}
std::cout<<"Hello World!!!!"<<std::endl;
deadline_timer t(io, boost::posix_time::seconds(5));
}
void func() {
}
int main() {
deadline_timer t(io, boost::posix_time::seconds(5));
t.async_wait(callback);
boost::asio::io_service::work work(io);
boost::asio::detail::thread worker(boost::bind(&boost::asio::io_service::run, &io));
while(1) {
io.post(func);
}
return 0;
}