Results 1 to 12 of 12

Thread: Sleep freezes everything?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Sleep freezes everything?

    i have a loop

    while(true)
    {
    cout<<".";
    Sleep(60000);
    }

    which should print a period every minute. but i get nothing, even when i turn it down to 100 i get nothing. why?

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    No idea right now....but just wondering. I have never used Sleep before in C++ only in Bach. But if I add it it says undecleared indentifier...do I have to include anything to use it? MSDN doesn't say anything abou it...

  3. #3
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Forgett about it.....Windows.h. it was...


    [Edit]But now I am getting linking problems....[/Edit]

    Linking...
    LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
    Debug/sleep.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

  4. #4
    Addicted Member
    Join Date
    Aug 2003
    Location
    USA
    Posts
    145
    Sleep freezes the current thread (thread the function was called from) and all execution within that thread until the interval is up.

    I believe using SleepEx API returns a value when the thread continues (interval for function is up).

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I think he knows that....but it should print something every minute.....or at least about every minute.It might be slowed down a bit of the system. But it is not supposed to freeze the whole app.

  6. #6
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    i think there is a function called delay - u may use that instead of sleep...


    also if it is not priniting even a single '.', check if it goes inside the loop or not... although it seems that it should....
    Regards

  7. #7
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I have no idea how the cout is actually working. But is it always flushing the buffer like println in java? If not....maybe the loop is to tight so it is never able to flush the buffer?

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It's not flushing. Insert a flush in the stream.

    cout << '.' << flush;
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Hehe...ohhh myyy good...my JAVA knowledge is good as gold...

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by CornedBee
    It's not flushing. Insert a flush in the stream.

    cout << '.' << flush;
    << endl; will flush the buffer

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But endl also inserts a newline, and if I understand Steve correctly, he wants an app that slowly builds a long chain of dots.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah but it will add a "\n" to it too first
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width