Chat with our AI personalities
Unfortunately, there is no cross-platform method of forcing a delay. Microsoft uses the sleep function (with a 1 second resolution) while UNIX uses usleep (with 1 nanosecond resolution). However, neither method can be regarded as being accurate in a multi-processing environment -- both will sleep for "at least" the given time, but if the system is busy your application will continue to sleep until its next time-slice comes around. Although usleep has a resolution of 1 nanosecond (1 billionth of a second), the system's frequency determines the actual resolution. For instance if your system has a frequency of 25 million ticks per second, your resolution is only 25 microseconds, so you cannot sleep for any less than that. Plus you have to add on the time it takes to make the call. C++11 provides much better support for hi-resolution timers in the <chrono> header, so at least we now have a portable method of sleeping for a preset duration. However the duration is still "at least" -- background tasks can still prevent your program from waking up on time. The following example demonstrates how to print the current time and how to put your program to sleep for a duration. Note that we still have no portable method of obtaining the current time in a thread-safe manner -- but the code includes a portable workaround. #include<iostream> // std::cout, std::endl #include<iomanip> // std::put_time #include<sstream> // std::stringstream #include<chrono> // std::chrono (C++11) #include<thread> // std::this_thread (C++11) namespace my_std { // std::localtime is not thread-safe but there is // no portable alternative in the standard. Thus // we must define our own standards... tm localtime (const std::time_t& time) { std::tm snapshot; #if (defined (WIN32) defined (_WIN32) defined (__WIN32__)) localtime_s (&snapshot, &time); // Microsoft-specific #else localtime_r (&time, &snapshot); // POSIX #endif return snapshot; } }; // Returns the current time and date as a string. std::string current_time_and_date() { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); time_t as_time_t = std::chrono::system_clock::to_time_t (now); std::stringstream ss; ss << std::put_time (&my_std::localtime (as_time_t), "%Y-%m-%d %X"); return ss.str(); } int main() { std::cout << "The current time is: " << current_time_and_date() << std::endl; std::cout << "Taking a nap for half-a-second..." << std::endl; std::this_thread::sleep_for (std::chrono::milliseconds (500)); // half-a-second std::cout << "The current time is: " << current_time_and_date() << std::endl; // 5-second ticker... std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); for (unsigned tick=0; tick<5; ++tick) { std::this_thread::sleep_until (now + std::chrono::seconds (tick)); std::cout << "Tick..." << std::endl; } std::this_thread::sleep_until ( now + std::chrono::seconds (5)); std::cout << "BOOM!" << std::endl; }
One of the most SEO strategy is improving your Google organic search rankings. Despite the fact that Google constantly tweaks their search engine algorithm, there are some fundamental best practices to get you started on improving it.some best techniques for seo :1. Map Strategy To Audience & Competitive Insights2. Align Your Content & SEO Teams3. Make Mobile SEO A Priority4. Find Measurement & Reporting That Works5. Integrate SEO Data Across Teams