Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   waiting period (http://www.velocityreviews.com/forums/t742557-waiting-period.html)

Hans Vlems 01-25-2011 04:03 PM

waiting period
 
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

David Resnick 01-25-2011 04:11 PM

Re: waiting period
 
On Jan 25, 11:03*am, Hans Vlems <hvl...@freenet.de> 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

Angel 01-25-2011 04:16 PM

Re: waiting period
 
On 2011-01-25, Hans Vlems <hvlems@freenet.de> 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.

Hans Vlems 01-25-2011 07:50 PM

Re: waiting period
 
On 25 jan, 17:16, Angel <angel+n...@spamcop.net> wrote:
> On 2011-01-25, Hans Vlems <hvl...@freenet.de> 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

robertwessel2@yahoo.com 01-25-2011 09:03 PM

Re: waiting period
 
On Jan 25, 10:03*am, Hans Vlems <hvl...@freenet.de> 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).

Seebs 01-26-2011 12:40 AM

Re: waiting period
 
On 2011-01-25, Hans Vlems <hvlems@freenet.de> 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 / usenet-nospam@seebs.net
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.

Michael Mouse 01-26-2011 02:19 AM

Re: waiting period
 
On 26 Jan 2011 00:40:10 GMT, Seebs <usenet-nospam@seebs.net> 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.



copx 01-26-2011 10:30 AM

Re: waiting period
 


"Michael Mouse" wrote in message
news:501vj69n0p7li8f0spu3iig1g0igg9f0on@4ax.com...
>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.


Eric Sosman 01-26-2011 12:40 PM

[OT] Re: waiting period
 
On 1/26/2011 5:30 AM, copx wrote:
>
>
> "Michael Mouse" wrote in message
> news:501vj69n0p7li8f0spu3iig1g0igg9f0on@4ax.com...
>> 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
esosman@ieee-dot-org.invalid

Kenny McCormack 01-26-2011 12:56 PM

Re: [OT] Re: waiting period
 
In article <ihp4nh$5tn$1@news.eternal-september.org>,
Eric Sosman <esosman@ieee-dot-org.invalid> wrote:
>On 1/26/2011 5:30 AM, copx wrote:
>>
>>
>> "Michael Mouse" wrote in message
>> news:501vj69n0p7li8f0spu3iig1g0igg9f0on@4ax.com...
>>> 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)



All times are GMT. The time now is 04:32 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.