473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

alarm against infinit loop

Hi guys,
is there any utility available as a protection against endless_loop()

something like this:

alarm.set(5); //set timeout for 5 sec

endless_loop();

alarm.reset(); //reset it to 0, as alarm not needed any more

Thanks,

Dec 1 '06 #1
3 3495

<an*****@yahoo.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi guys,
is there any utility available as a protection against endless_loop()

something like this:

alarm.set(5); //set timeout for 5 sec

endless_loop();

alarm.reset(); //reset it to 0, as alarm not needed any more

Thanks,
Perhaps there exists such a utility, but as it
would not be standard C++, it would not be topical
here. However, a simple way to implement this would
involve instrumenting the loop itself. Before
the loop begins, capture a time with std::clock(),
and at one or more points inside the loop, capture
the time again. The difference between it and the
one obtained outside the loop would give elapsed time.
Compare it with your desired 'time-out' value. Break
the loop if elapsed time >= your time-out value.

See standard library documentation for details on
how to use 'std::clock()'.

-Mike
Dec 1 '06 #2


On Dec 2, 7:13 am, anki...@yahoo.com wrote:
Hi guys,
is there any utility available as a protection against endless_loop()

something like this:

alarm.set(5); //set timeout for 5 sec

endless_loop();

alarm.reset(); //reset it to 0, as alarm not needed any more
pesudo code:

int flag = 0;

main(){
signal(SIGALRM, alarm_handler)
while (1) {
if (flag == 1)
break;
}
}

void alarm_handler()
{
flag = 1;
}

Actually, alarm signal will break the blocked system call.
Thanks,
Dec 2 '06 #3
an*****@yahoo.com wrote:
Hi guys,
is there any utility available as a protection against endless_loop()
Testing?

Anything else would be either intrusive, or platform specific
(signals/watchdog timers).

--
Ian Collins.
Dec 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bill H | last post by:
I have a typical username/password check against mysql type logon that Zone Alarm Pro seem to break... I haven't bought or troubleshooted this yet, I'm hoping this is a know issue with a simple...
13
by: na1paj | last post by:
here's a simple linked list program. the DeleteNode function is producing an infinit loop i think, but i can't figure out where.. #include <stdio.h> typedef struct { char *str; //str is a...
1
by: Sergey | last post by:
How to send alarm to a thread? I can set alarm in main thread, but how then send exception to another thread to wake it if it executes too long?
7
by: Adrian Casey | last post by:
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is...
0
by: puntino | last post by:
Hi I have developed an Alarm, I haven' problem of runtime or compiletime but the application seems blocked. When I call the method AlarmExecute, it runs only the first time ( when i click onto run...
0
by: thelightkeeper | last post by:
Hi, in MSSQL, I have 2 tables naming , --------------------------------------- EquipmentID : nvarchar(50), FK, reference .EquipmentID AlarmID : nvarchar(50), PK AlarmHappenTime :...
2
by: Alan Isaac | last post by:
Goal: turn off an audible alarm without terminating the program. For example, suppose a console program is running:: while True: sys.stdout.write('\a') sys.stdout.flush() time.sleep(0.5) ...
0
by: Alexnb | last post by:
I am wondering what is the best way to create a timer, like an alarm, once it reaches a time, it triggers an event. I have a way of doing this but it seems like it isn't good at all. If it helps at...
8
by: superleochen | last post by:
Database is simliar to this: ID TIME TAGNAME VALUE 5967383 8/1/2008 1:00:24 AM I16MUDL11 ALARM 5967384 8/1/2008...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.