Portable nonbusy hold?

This is a discussion on Portable nonbusy hold? within the C Programming forums, part of the General Programming Boards category; Can it be done? Background: As we all know, there are a gajillion ways of inserting delay into a program, ...

  1. #1
    Evil Member
    Join Date
    Jan 2002
    Posts
    638

    Portable nonbusy hold?

    Can it be done?

    Background:

    As we all know, there are a gajillion ways of inserting delay into a program, from superfluous for loops that do nothing, to the more sophisticated time(NULL)-split>howLong method, and then there are nonportables such as windows.h's Sleep(), and the myriad of sleep()'s, delay()'s and _delay()'s found in compilers.

    My question:

    Is there any way to make a portable, nonbusy hold?

    My current code does this:

    Code:
    void holdOnThere(int howLongToWait) { 
    
    time_t split = time(NULL); 
    
    while (time(NULL) - split < howLongToWait) { } 
    
    return; 
    
    }
    Which is a portable(mostly) but busy wait. I think windows.h's Sleep() is nonbusy, but it isn't portable.

    Is there any way to get both in one construct, and if so, how?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    AFAIK its not possible to do this in a portable way. You will always need to use the features of your chosen operating system to do this.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Evil Member
    Join Date
    Jan 2002
    Posts
    638

    That was my interpretation as well

    But the only dumb question is the one not asked...

    I was considering maybe using a wrapper function and conditional compilation directives to simulate portability, but I'd still need the appropriate calls for each OS.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 08:38 AM
  2. C - Portable?
    By vb.bajpai in forum C Programming
    Replies: 2
    Last Post: 07-15-2007, 09:09 AM
  3. Portable Audio Library
    By CornedBee in forum C++ Programming
    Replies: 2
    Last Post: 05-19-2005, 02:09 AM
  4. which Portable mp3 player?
    By Raihana in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 01-09-2004, 06:58 AM
  5. Replies: 1
    Last Post: 03-21-2002, 05:10 PM

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