sleep in main..Unexepcted result

1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
using namespace 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


Please help

Thanks in advance
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^^)
Topic archived. No new replies allowed.