Windows ginput function [Was: fopen doesn't return when opening a fifo!!]
David Bateman
David.Bateman at motorola.com
Wed Apr 2 12:11:57 CDT 2008
John W. Eaton wrote:
> On 2-Apr-2008, David Bateman wrote:
>
> | Then we need to have O_NONBLOCK set on the output pipe and use a while
> | loop to probe for input.. This wait loop in Octave will however
> | needlessly consume CPU cycles.. I have that version of the code as well
> | if you'd prefer.
>
> It is only in this loop while ginput is active, right? What about
> sleeping for 0.1s each time through the loop? Would that be
> acceptable?
>
Yes its only in the wait loop when ginput is active. For sleeping to
reduce the CPU load it needs to be much longer than a time slice of the
processor. The HZ variable in the linux kernel sets this value to
typically 10ms. Therefore yes a 100ms sleep might reduce the CPU usage.
However in octave, sleep(0.1) will ultimately call the libc usleep
function, and this is implemented with a wait loop in any case. Try
while (true), usleep(0.1); end
and check the CPU load.. So doing this won't gain you anything.
Additionally what if the user is a fast clicker, and is faster than the
arbitrary 0.1s delay. This will result in missed clicks.. I therefore
thinks its better to not sleep, or use blocking reads.
I believe the attached patch should work as you'd like it to.
D.
--
David Bateman David.Bateman at motorola.com
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch7883
Url: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080402/fbf17984/attachment.ksh
More information about the Bug-octave
mailing list