Timing the work execution using the timer class
There is a class in the Boost C++ library that provides the ability to conduct a blocking or asynchronous wait for a timer until it expires, known as the deadline timer. A deadline timer indicates one of two states: expired or not expired.
An expiring timer
Here, we are going to create a timer that will expire in 10 seconds. Let us take a look at the following code:
/* timer.cpp */ #include <boost/asio.hpp> #include <boost/shared_ptr.hpp> #include <boost/thread.hpp> #include <boost/thread/mutex.hpp> #include <boost/bind.hpp> #include <iostream> boost::mutex global_stream_lock; void WorkerThread(boost::shared_ptr<boost::asio::io_service> iosvc, int counter) { global_stream_lock.lock(); std::cout << "Thread ...
Get Boost.Asio C++ Network Programming - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.