Thread: Need something better than sleep()

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Bladactania View Post
    Well, I would have liked to not be using the CPU during the delay, but since I don't need the CPU to really be doing anything else during this time, then it's not that big a deal... out of curiosity, does the sleep function is dos.h use the CPU as well?
    If it's a DOS function, there is no multitasking, so there is nothing that would happen instead, so yes.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    That is unfortunate. But I guess there's no way around it.

    Thanks.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Bladactania View Post
    That is unfortunate. But I guess there's no way around it.

    Thanks.
    Well, I guess you could rewrite the code to be Windows-compatible instead of using very ancient DOS...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    I'm limited by the computer the code will be running on. I'm writing code to run on a Single Board Computer running a 133Mhz Processor with about 32MB of memory...

  5. #20
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Bladactania View Post
    I'm limited by the computer the code will be running on. I'm writing code to run on a Single Board Computer running a 133Mhz Processor with about 32MB of memory...
    Right. So if you are going to use more than about 2% of the 32MB, you will need a different OS than DOS.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #21
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    Wait... What?

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    DOS is limited to 640KB (well, ok the first 1MB, but the last 384KB of "DOS" memory is occupied by the BIOS, Video Memory and such things, so the application has a bit less than 640 KB to play with, since the first little bit of memory is occupied by vector table and the actual DOS kernel).

    There are ways around it, but it gets messy very quickly.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #23
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    DOS is limited to 640KB (well, ok the first 1MB, but the last 384KB of "DOS" memory is occupied by the BIOS, Video Memory and such things, so the application has a bit less than 640 KB to play with, since the first little bit of memory is occupied by vector table and the actual DOS kernel).
    Obviously that can't be true considering my first computer ran DOS with 4MB of RAM

    Read more about this here. There are several ways to overcome the 640K barrier (back in the day, I used XMS). Chances are that whatever DOS version you are using supports a DOS extender of some kind. If you are using a version of DOS prior to 3.0, then things might get kind of tricky though.

  9. #24
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by bithub View Post
    Obviously that can't be true considering my first computer ran DOS with 4MB of RAM

    Read more about this here. There are several ways to overcome the 640K barrier (back in the day, I used XMS). Chances are that whatever DOS version you are using supports a DOS extender of some kind. If you are using a version of DOS prior to 3.0, then things might get kind of tricky though.
    DOS memory extenders require cooperation from the application. You don't just plug it in and magically get access to more memory.

    If DOS is a requirement, I'd calibrate a busy-loop to do subsecond waiting.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  10. #25
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    DOS memory extenders require cooperation from the application. You don't just plug it in and magically get access to more memory.
    Nowhere did I imply there was magic involved, I just stated that is was possible (and relatively common to do).

    If DOS is a requirement, I'd calibrate a busy-loop to do subsecond waiting.
    How is that an improvement over calling the delay() function?

  11. #26
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by bithub View Post
    Nowhere did I imply there was magic involved, I just stated that is was possible (and relatively common to do).

    How is that an improvement over calling the delay() function?
    How do you know you will have this function? The OP indicated targetting some custom environment.

    Where would you even acquire a DOS memory extender? None of those companies are still in business.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  12. #27
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by brewbuck View Post
    Where would you even acquire a DOS memory extender? None of those companies are still in business.
    Kids these days! Back in my day we had himem.sys and emm386.sys ... both of which came with DOS.


    Quzah.
    Hope is the first step on the road to disappointment.

  13. #28
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by quzah View Post
    Kids these days! Back in my day we had himem.sys and emm386.sys ... both of which came with DOS.


    Quzah.
    Yes, but beyond that, you need the compiler to produce code that uses the extended memory. Most DOS applications didn't actually USE memory above 1MB, it was mainly used as disk-cache.

    Note that to use memory above 1MB, the application code needs to run in protected mode, and to get above 16MB, it is necessary to have 32-bit protected mode. Neither of the protected modes are compatible with real-mode that DOS runs in, so basically, any interrupts have to be turned off whilst in protected mode. This also means no calls to BIOS, no reading/writing from/to hard-disk, etc, etc. It is non-trivial to run in protected mode and DOS at the same time.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #29
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm pretty sure DOOM used more than 1 MB of memory, and that it read from files, and could read key interrupts. Pardon me while I disagree with you.

    Speak of the devil, here it is now: DOS extender - Wikipedia, the free encyclopedia

    Perhaps I'm misunderstanding your statement, but again, I'm pretty sure DOOM handled keyboard interrupts just fine, and that it read from disk...


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #30
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,786
    Quote Originally Posted by quzah View Post
    I'm pretty sure DOOM used more than 1 MB of memory, and that it read from files, and could read key interrupts. Pardon me while I disagree with you.

    Speak of the devil, here it is now: DOS extender - Wikipedia, the free encyclopedia

    Perhaps I'm misunderstanding your statement, but again, I'm pretty sure DOOM handled keyboard interrupts just fine, and that it read from disk...


    Quzah.
    DOOM was loading it own memory manager if I remember correctly. I do not know was it was doing, but it was one of the first programs doing it...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [pthread] cancellable sleep in win32?
    By cyberfish in forum C++ Programming
    Replies: 2
    Last Post: 08-11-2007, 02:30 AM
  2. Sleep works with just one thread, but not 2
    By finkus in forum C++ Programming
    Replies: 5
    Last Post: 12-01-2005, 09:17 PM
  3. Problem with Sleep() #$@^#$%^
    By intruder in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 06:46 AM
  4. why do we require sleep?
    By jinx in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 07-14-2004, 08:21 AM
  5. Sleep is overrated...
    By Polymorphic OOP in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 01-24-2003, 12:40 PM