delay

A

asit

In my multi threaded application(windows), I have several infinite
loop(though it's not good to have...but I need them). Hence they eat
nearly 98% of CPU time(it shows in task manager).

I have decided to put a delay of 200 ms in the program. But
unfortunately my Compiler(Borland 5.5) is not providing any such
functionalities.

In my research, I found that many (lame) people put delay by putting
unnecessary instructions in the delay block....like this

void delay()
{
int i=0,j=10;
for(i=0;i<12345678;i++)
j *=j;
}

But it won't do my job. But I have found that by doing some kind of
signal handling, I can create my delay function.

Does such functionality is available in windows ????
How can I implement it ????
 
A

Antoninus Twink

In my multi threaded application(windows), I have several infinite
loop(though it's not good to have...but I need them). Hence they eat
nearly 98% of CPU time(it shows in task manager).

I have decided to put a delay of 200 ms in the program. But
unfortunately my Compiler(Borland 5.5) is not providing any such
functionalities.

But it won't do my job. But I have found that by doing some kind of
signal handling, I can create my delay function.

Does such functionality is available in windows ????
How can I implement it ????

On POSIX systems, the function you're looking for is called sleep(3) and
can be implemented using the SIGALRM signal.

Doing a Google search for
"Windows API" sleep
shows that the corresponding Windows function is called Sleep with a
capital S, and takes a long int argument specifying the length of time
to wait in milliseconds.
 
I

Ian Collins

Antoninus said:
On POSIX systems, the function you're looking for is called sleep(3) and
can be implemented using the SIGALRM signal.
Utter nonsense. sleep(3) suspendeds execution for a number of seconds.
The correct POSIX function would be nanosleep(). SIGALRM is a total
red herring.
 
A

Antoninus Twink

Utter nonsense. sleep(3) suspendeds execution for a number of
seconds. The correct POSIX function would be nanosleep().

As usual, you deliberately misunderstand.

The OP's question was about Windows, and the only point of mentioning
POSIX was to find the correct synonymn for delay (namely sleep) that
results in a successful Google search.

Try googling
"Windows API" nanosleep
and see how useful the results are.
SIGALRM is a total red herring.

The OP asked whether delay functions can be implemented using signals.
In principle, the answer is clearly yes, as demonstrated by alarm(2).
The fact that its argument is a time in seconds doesn't change the fact
that it works by delivering a SIGALRM to the calling process.
 
A

Antoninus Twink

The problem is that i don't use Visual C++, I use Borland C++ 5.0.

Surely you can access the Windows standard library with any C or C++
compiler?
 
N

Nick Keighley

The problem is that i don't use Visual C++, I use Borland C++ 5.0.

the problem is you are on the wrong news group.
Please post your problem to a suitable Microsoft newsgroup.
 
A

asit

the problem is you are on the wrong news group.
Please post your problem to a suitable Microsoft newsgroup.

thanx friends....

finally I solved my problem.
the required function is Sleep(int milisec)
now my keylogger is not eating much resources ...
 
N

Nate Eldredge

[off-topic]

Antoninus Twink said:
The OP asked whether delay functions can be implemented using signals.
In principle, the answer is clearly yes, as demonstrated by alarm(2).
The fact that its argument is a time in seconds doesn't change the fact
that it works by delivering a SIGALRM to the calling process.

Certainly sleep(3) can be implemented via alarm(2), and historically
has been, but isn't always. On my system it just calls nanosleep(2).
 
J

jacob navia

Antoninus said:
Surely you can access the Windows standard library with any C or C++
compiler?
Sleep is a basic windows function accessible from both compilers.
 
K

Keith Thompson

asit said:
In my multi threaded application(windows), I have several infinite
loop(though it's not good to have...but I need them). Hence they eat
nearly 98% of CPU time(it shows in task manager).

I have decided to put a delay of 200 ms in the program. But
unfortunately my Compiler(Borland 5.5) is not providing any such
functionalities.
[...]

Questions about Windows-specific functions will generally get better
and quicker answers in comp.os.ms-windows.programmer.win32 or in one
of the microsoft.* groups.
 
C

CBFalconer

jacob said:
Sleep is a basic windows function accessible from both compilers.

The point is the 'sleep' is not an available function in standard
C. If you want it available, go to a newsgroup that deals with
whatever non-standard system you are using. It is off-topic on
c.l.c. You will have a hard time accessing the Windows standard
library on a Linux system, for example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,733
Latest member
LonaMonzon

Latest Threads

Top