Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > waiting period

Reply
Thread Tools

waiting period

 
 
Hans Vlems
Guest
Posts: n/a
 
      01-25-2011
Problem description: the program modifies files and the filesystem is
somewhat slow.
More specifically, two subsequent calls on the rename function for one
file fail because the filesystem is slowed down for reasons unknown.
Waiting for one second is sufficient to avoid this effect. My somewhat
crude workaround is a wait function that implements a busy form of
waiting:

starttime=time(NULL);
while (difftime(time(NULL),starttime)<2) // wait 2 seconds
{
... calculates sin() and pow() many times
}

Is there a more elegant way to suspend a program for specific period
of time (accuracy: seconds) ?

The compiler in use is GCC 4.4.4 for Windows (the djgpp distribution
that runs in command line mode).
Hans
 
Reply With Quote
 
 
 
 
David Resnick
Guest
Posts: n/a
 
      01-25-2011
On Jan 25, 11:03*am, Hans Vlems <(E-Mail Removed)> wrote:
> Problem description: the program modifies files and the filesystem is
> somewhat slow.
> More specifically, two subsequent calls on the rename function for one
> file fail because the filesystem is slowed down for reasons unknown.
> Waiting for one second is sufficient to avoid this effect. My somewhat
> crude workaround is a wait function that implements a busy form of
> waiting:
>
> *starttime=time(NULL);
> *while (difftime(time(NULL),starttime)<2) * // wait 2 seconds
> *{
> * * ... calculates sin() and pow() many times
> *}
>
> Is there a more elegant way to suspend a program for specific period
> of time (accuracy: seconds) ?
>
> The compiler in use is GCC 4.4.4 for Windows (the djgpp distribution
> that runs in command line mode).
> Hans


There is no portable way other than a busy loop. But nobody
recommends busy loops.
Here: http://c-faq.com/osdep/subsecond.html are listed some of the OS
dependent ways to do it...

-David
 
Reply With Quote
 
 
 
 
Angel
Guest
Posts: n/a
 
      01-25-2011
On 2011-01-25, Hans Vlems <(E-Mail Removed)> wrote:

> Is there a more elegant way to suspend a program for specific period
> of time (accuracy: seconds) ?
>
> The compiler in use is GCC 4.4.4 for Windows (the djgpp distribution
> that runs in command line mode).
> Hans


On POSIX-compliant systems you can use sleep(). Don't know if the above
setup is POSIX-compliant though, I only work with Linux.


--
The natural state of a spammer's website is a smoking crater.
 
Reply With Quote
 
Hans Vlems
Guest
Posts: n/a
 
      01-25-2011
On 25 jan, 17:16, Angel <(E-Mail Removed)> wrote:
> On 2011-01-25, Hans Vlems <(E-Mail Removed)> wrote:
>
> > Is there a more elegant way to suspend a program for specific period
> > of time (accuracy: seconds) ?

>
> > The compiler in use is GCC 4.4.4 for Windows (the djgpp distribution
> > that runs in command line mode).
> > Hans

>
> On POSIX-compliant systems you can use sleep(). Don't know if the above
> setup is POSIX-compliant though, I only work with Linux.
>
> --
> The natural state of a spammer's website is a smoking crater.


Thanks, I found a reference to sleep() in unistd.h!
Hans
 
Reply With Quote
 
robertwessel2@yahoo.com
Guest
Posts: n/a
 
      01-25-2011
On Jan 25, 10:03*am, Hans Vlems <(E-Mail Removed)> wrote:
> Problem description: the program modifies files and the filesystem is
> somewhat slow.
> More specifically, two subsequent calls on the rename function for one
> file fail because the filesystem is slowed down for reasons unknown.
> Waiting for one second is sufficient to avoid this effect. My somewhat
> crude workaround is a wait function that implements a busy form of
> waiting:
>
> *starttime=time(NULL);
> *while (difftime(time(NULL),starttime)<2) * // wait 2 seconds
> *{
> * * ... calculates sin() and pow() many times
> *}
>
> Is there a more elegant way to suspend a program for specific period
> of time (accuracy: seconds) ?
>
> The compiler in use is GCC 4.4.4 for Windows (the djgpp distribution
> that runs in command line mode).
> Hans



While other folks have commented on your actual question, you have a
different issue here. There really aren't any issues like you
describe in Window, and it's certainly hard to imagine ones that would
be "fixed" with a wait of a second or two. It's more likely you're
hitting some race condition in your application (are you using
asynchronous I/O or threads to do the mods?) or in the DJGPP mapping
layer (although that's somewhat less likely).

Whatever it is, patching around what is almost certainly a problem in
your application is a really bad idea, and might very well come back
to haunt you if you run on a different machine that alters the timing
enough to generate the problem again).
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      01-26-2011
On 2011-01-25, Hans Vlems <(E-Mail Removed)> wrote:
> Problem description: the program modifies files and the filesystem is
> somewhat slow.


> More specifically, two subsequent calls on the rename function for one
> file fail because the filesystem is slowed down for reasons unknown.


Stop!

Find out what is actually happening here. Otherwise, all that will happen
is you'll have more erratic behavior later -- say, you'll have something
that blows up in the afternoons, or only during peak Netflix streaming
hours, or on Fridays in Lent.

It is fine to work around a problem *once you know what it is*. You should
never let "reasons unknown" fester in your project.

> Waiting for one second is sufficient to avoid this effect. My somewhat
> crude workaround is a wait function that implements a busy form of
> waiting:


Don't do that. The solution depends on your host environment, but I don't
think there's anything out there on which there isn't a better solution.

> Is there a more elegant way to suspend a program for specific period
> of time (accuracy: seconds) ?


Yes.

> The compiler in use is GCC 4.4.4 for Windows (the djgpp distribution
> that runs in command line mode).


You might try a Windows group, or see whether it has a sleep() function,
since I seem to recall that one of the popular gcc-for-Windows distributions
includes some Unixy stuff.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
Michael Mouse
Guest
Posts: n/a
 
      01-26-2011
On 26 Jan 2011 00:40:10 GMT, Seebs <(E-Mail Removed)> wrote:

>> The compiler in use is GCC 4.4.4 for Windows (the djgpp distribution
>> that runs in command line mode).


DJGPP is for DOS and that may be the problem, running a DOS program
under NT based Windows.


 
Reply With Quote
 
copx
Guest
Posts: n/a
 
      01-26-2011


"Michael Mouse" wrote in message
news:(E-Mail Removed)...
>DJGPP is for DOS and that may be the problem, running a DOS program
>under NT based Windows.


Indeed. DJGPP is a DOS compiler. The current version of Windows (Windows 7)
may execute this or that DOS app, but it probably won't work correctly.
DJGPP is only stable on DOS and to a lesser extend on Windows 9x.

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      01-26-2011
On 1/26/2011 5:30 AM, copx wrote:
>
>
> "Michael Mouse" wrote in message
> news:(E-Mail Removed)...
>> DJGPP is for DOS and that may be the problem, running a DOS program
>> under NT based Windows.

>
> Indeed. DJGPP is a DOS compiler. The current version of Windows (Windows 7)
> may execute this or that DOS app, but it probably won't work correctly.
> DJGPP is only stable on DOS and to a lesser extend on Windows 9x.


(Shrug.) Works fine for me on XP. Then again, I'm not trying
to rename() the same file forty-leven times in three milliquivers,
either. YMMV.

--
Eric Sosman
(E-Mail Removed)lid
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      01-26-2011
In article <ihp4nh$5tn$(E-Mail Removed)-september.org>,
Eric Sosman <(E-Mail Removed)> wrote:
>On 1/26/2011 5:30 AM, copx wrote:
>>
>>
>> "Michael Mouse" wrote in message
>> news:(E-Mail Removed)...
>>> DJGPP is for DOS and that may be the problem, running a DOS program
>>> under NT based Windows.

>>
>> Indeed. DJGPP is a DOS compiler. The current version of Windows (Windows 7)
>> may execute this or that DOS app, but it probably won't work correctly.
>> DJGPP is only stable on DOS and to a lesser extend on Windows 9x.

>
> (Shrug.) Works fine for me on XP.


The implication seems to be that in Vista/Windows7/whatever, they (MS)
are going to actually remove DOS support. There are political reasons
why some people like to push this as an agenda, but I doubt it will ever
really happen.

>Then again, I'm not trying
>to rename() the same file forty-leven times in three milliquivers,
>either. YMMV.


heh heh. Good one.

--
Religion is regarded by the common people as true,
by the wise as foolish,
and by the rulers as useful.

(Seneca the Younger, 65 AD)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VoIPCheap/Stunt/SIPDiscount/Et.al - Mobile - Top-up Expiry Period -- Campaign for Correct Expiry Period on Finarea VOIP Service Mobile Top-Ups News Reader UK VOIP 16 06-26-2006 05:03 PM
Testking.co.uk study guides now for $29 for a limited period only Moderator Microsoft Certification 0 12-07-2005 05:19 PM
All new exams added in testking.co.uk now at half prices for limited period only Moderator Microsoft Certification 2 12-06-2005 10:12 AM
Testking.co.uk study guides for $29 for a limited period with all new added exams Moderator Microsoft Certification 2 12-05-2005 09:57 AM
Linux . How to let a Thread sleep for a period of time waiting for an event Douwe C Programming 3 08-23-2003 02:44 AM



Advertisments