#include<iostream>
usingnamespace std;
#include<unistd.h>
int main()
{
cout<<"I am in main about to sleep"<<endl;
sleep(5);
cout<<" I woke up"<<endl;
return 0;
}
I wrote the above program and it gives completely unexpected result when I run it
Output:
1 2 3
I am in main about to sleep
I am in main about to sleep
I am in main about to sleep
It displaying first statement 3 times.I am clueless and doesnt have a slightest idea what the output is
Strange:P In any case, in c++11 you now have std::this_thread::sleep_for(std::chrono::milliseconds(msToSleep));, which is not platform-specific (and therefore better^^)