Re: Implementing a Timeout in C/C++
- From: Roger Leigh <${rleigh}@invalid.whinlatter.ukfsn.org.invalid>
- Date: Thu, 16 Mar 2006 00:02:17 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
wade.lindsey@xxxxxxxxx writes:
basically, a straitforward timeout...
Is there anyway to achieve this without using sleep? I have other
actions going on in the background that I don't want to suspend, I just
want a max-timed while loop - is that possible?? Trivial??
setitimer(2) or alarm(2) are good choices.
Install an SIGALRM signal handler, and use that to break out of the
loop by setting a condition variable of type sig_atomic_t.
Example:
http://cvs.alioth.debian.org/cgi-bin/cvsweb.cgi/schroot/schroot/sbuild-auth-conv-tty.h?rev=1.11&content-type=text/x-cvsweb-markup&cvsroot=buildd-tools
http://cvs.alioth.debian.org/cgi-bin/cvsweb.cgi/schroot/schroot/sbuild-auth-conv-tty.cc?rev=1.17&content-type=text/x-cvsweb-markup&cvsroot=buildd-tools
This is a password entry for TTYs, to hook into PAM. It uses a timer
to implement two timeouts: a warning timeout, and a fatal timeout.
In this case, there isn't a loop, it interrupts a read(2) system call,
but it could easily have been
while (!timer_expired)
{
...
}
Regards,
Roger
- --
Roger Leigh
Printing on GNU/Linux? http://gutenprint.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8+ <http://mailcrypt.sourceforge.net/>
iD8DBQFEGKsGVcFcaSW/uEgRAv4LAKDSXA1joJ4MU6ozUpWfQ7UrJWIGCwCgxv9e
SeXC1NiXUUFui8cEU9xwklw=
=Oj7c
-----END PGP SIGNATURE-----
.
- References:
- Implementing a Timeout in C/C++
- From: wade . lindsey
- Implementing a Timeout in C/C++
- Prev by Date: Re: removing a loop cause it to go at half the speed?
- Next by Date: a unix script to send email notification when a sas batch job fails?
- Previous by thread: Implementing a Timeout in C/C++
- Next by thread: Re: Implementing a Timeout in C/C++
- Index(es):
Relevant Pages
|