As long as we're on the subject, it's worth noting that usleep isn't a standard UNIX function. "nanosleep" is.
but it is recommended to use select() with NULLs and a timeval struct instead, i was told once.
martin
On Sun, 12 May 2002 jdavison@speakeasy.org wrote:
As long as we're on the subject, it's worth noting that usleep isn't a standard UNIX function. "nanosleep" is.
-- John Davison, jdavison at-sign speakeasy period org
martin pi attacksyour.net/pi
johann strauss gasse 32 | 7 1040 vienna ++43 699 10 44 37 42
sil.at
I recommend using sys_microsleep from m_imp.h, ...
Guenter
On Mon, 13 May 2002, martin pi wrote:
but it is recommended to use select() with NULLs and a timeval struct instead, i was told once.
martin
On Sun, 12 May 2002 jdavison@speakeasy.org wrote:
As long as we're on the subject, it's worth noting that usleep isn't a standard UNIX function. "nanosleep" is.
-- John Davison, jdavison at-sign speakeasy period org
martin pi attacksyour.net/pi
johann strauss gasse 32 | 7 1040 vienna ++43 699 10 44 37 42
sil.at
My following remarks are UNIX-centric; for the purposes of this
discussion, I equate UNIX with the Open Group Base Specifications Issue 6/IEEE Std 1003.1-2001. See URL "http://www.opengroup.org/onlinepubs/007904975/nfindex.html" for more information.
Martin Pi writes:
but it is recommended to use select() with NULLs and a timeval struct instead, i was told once.
That's stale advice from pre-nanosleep/microsleep days. In UNIX and
UNIX-like systems, struct timeval provides microsecond resolution, and struct timespec provides nanosecond resolution. Therefore, other things equal, it's preferable to use a routine that uses struct timespec. Such routines are "clock_nanosleep" (see URL "http://www.opengroup.org/onlinepubs/007904975/functions/clock_nanosleep.html"), "nanosleep" (see URL "http://www.opengroup.org/onlinepubs/007904975/functions/nanosleep.html"), "pselect" (see URL "http://www.opengroup.org/onlinepubs/007904975/functions/select.html"), and "pthread_cond_timedwait" (see URL "http://www.opengroup.org/onlinepubs/007904975/functions/pthread_cond_timedwa...").
Not all UNIX or UNIX-like systems provide nontrivial implementations of
these routines, and some of the routines ("clock_nanosleep", "pselect") are new enough that the routines may not even exist in stub form. The usual compile-time and run-time checks must be done. For example, Darwin Version 5.4 in MacOS X 10.1.3 is lagging badly; it doesn't even have "nanosleep". One hopes that MacOS X 10.2 will bring us a version of Darwin that is at least up to 1998 standards. (The 1998 Single UNIX Specification, Version 2 had nanosleep -- see URLs "http://www.opengroup.org/onlinepubs/007908799/toc.htm" and "http://www.opengroup.org/onlinepubs/007908799/xsh/nanosleep.html".)
Guenter Geiger writes:
I recommend using sys_microsleep from m_imp.h, ...
I can't speak for Microsoft Windows, but to the best of my knowledge,
"sys_microsleep" and <m_imp.h> are vendor-specific; neither exists in the Open Group Base Specifications Issue 6/IEEE Std 1003.1-2001 (or any of its predecessors), SunOS 5.8, or Darwin Version 5.4. If a system has neither of these, a wrapper routine ought to exist which, based on compile-time and run-time checks, falls back on one of the alternatives listed above. (For example, with Darwin Version 5.4, one might fall back on "pthread_cond_timedwait", "usleep", or "select".)
hi !
Guenter Geiger writes:
I recommend using sys_microsleep from m_imp.h, ...
I can't speak for Microsoft Windows, but to the best of my knowledge,
"sys_microsleep" and <m_imp.h> are vendor-specific; neither exists in the Open Group Base Specifications Issue 6/IEEE Std 1003.1-2001 (or any of its predecessors), SunOS 5.8, or Darwin Version 5.4. If a system has neither of ...
exactly !!!
<m_imp.h> should read "m_imp.h" it is part of pd and is some kind of "wrapper". of course, this is not ieee-conformant, but -- hey -- we want to write software not standards.
mfg.cdsa.er IOhannes
But I recently discovered that select() works only if you have an open socket. So if you're running "-nogui" it won't do any timing for you unless you make your own (or startup a netreceive object).
cheers Miller
On Mon, May 13, 2002 at 01:30:40PM +0200, martin pi wrote:
but it is recommended to use select() with NULLs and a timeval struct instead, i was told once.
martin
On Sun, 12 May 2002 jdavison@speakeasy.org wrote:
As long as we're on the subject, it's worth noting that usleep isn't a standard UNIX function. "nanosleep" is.
-- John Davison, jdavison at-sign speakeasy period org
martin pi attacksyour.net/pi
johann strauss gasse 32 | 7 1040 vienna ++43 699 10 44 37 42
sil.at
Sorry, I should have said that this is my experience in W2K.
I've never seen a unix() that doesn't implement select() correctly!
As to sys_microsleep(), it's in Pd, not the OS, and has the good property that it wakes up if GUI or netreceive() input arrives while it's sleeping.
On that note, however, if you're writing a Pd extern it's probably better to use a clock_delay() callback; this way, teh rest of Pd won't hang while you wait.
cheers Miller
On Mon, May 13, 2002 at 09:43:27AM -0700, Miller Puckette wrote:
But I recently discovered that select() works only if you have an open socket. So if you're running "-nogui" it won't do any timing for you unless you make your own (or startup a netreceive object).
cheers Miller
On Mon, May 13, 2002 at 01:30:40PM +0200, martin pi wrote:
but it is recommended to use select() with NULLs and a timeval struct instead, i was told once.
martin
On Sun, 12 May 2002 jdavison@speakeasy.org wrote:
As long as we're on the subject, it's worth noting that usleep isn't a standard UNIX function. "nanosleep" is.
-- John Davison, jdavison at-sign speakeasy period org
martin pi attacksyour.net/pi
johann strauss gasse 32 | 7 1040 vienna ++43 699 10 44 37 42
sil.at
On that note, however, if you're writing a Pd extern it's probably better to use a clock_delay() callback; this way, teh rest of Pd won't hang while you wait.
except in the case where the extern is threaded like sonogram~ or cooled~ which was the starting point for all this thread ( without nanosleeps !! )
hem, well, very interesting all of these but i'm rather interested in the status of these objects for Windows ??
i'll set a link to them when they exist.
cheers,
yves