Sleep works with just one thread, but not 2

This is a discussion on Sleep works with just one thread, but not 2 within the C++ Programming forums, part of the General Programming Boards category; I'm trying to get a thread to check a file for updates, then sleep for half a second, then check ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    17

    Sleep works with just one thread, but not 2

    I'm trying to get a thread to check a file for updates, then sleep for half a second, then check again, and so on, until the loop gets a flag telling it to stop. The program compiles, but when it's running and it hits the Sleep call ( Sleep ( 500 ); ), I get this error in my console window:

    'sleep' is not recognized as an internal or external command, operable program, or batch file

    I have another call to Sleep earlier on, before the program splits to 2 threads, and it works just fine. They're called exactly the same way, so I'm assuming it has something to do with where it's being called from. The error message doesn't mean a whole lot to me, so I was hoping someone here might know what's going on.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    post code. I use Sleep() in multiple threads with no problems. Looks like you might have use "sleep" instead of "Sleep" (capital 'S') or ignored compiler errors/warnings.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    That error message sounds like you've done
    Code:
    system("Sleep");
    which would be the equiviliant of typing sleep into the console.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    in MS-Windows os does not have a sleep command, so system("sleep") would do nothing, unless you also have cygwin installed, then it is located in /usr/bin directory.

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    thanks for that link.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-26-2009, 10:48 PM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 07:50 AM
  4. Replies: 12
    Last Post: 05-17-2003, 05:58 AM
  5. Sleep is overrated...
    By Polymorphic OOP in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 01-24-2003, 11:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21