[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] (file-select ...) and compiler warnings
From: |
Jim Ursetto |
Subject: |
Re: [Chicken-users] (file-select ...) and compiler warnings |
Date: |
Sun, 17 Feb 2013 21:16:56 -0600 |
On Feb 17, 2013, at 4:18 PM, J Altfas wrote:
> Hello,
>
> Using 'file-select' as a sub-second sleep procedure works without hitch under
> csi:
>
> (define (sleeper tm)
> (let ((currms (current-milliseconds)))
> (let-values (((_ __) (file-select #f #f tm)))
> (print (- (current-milliseconds) currms)))))
>
> ;1> (sleeper 0.05)
> 50.0
Perhaps better is to use thread-sleep!, which does a select or poll behind the
scenes, but does not block other threads. file-select will block all threads
until the timeout occurs.
(use srfi-18)
(define (sleeper tm)
(let ((currms (current-milliseconds)))
(thread-sleep! tm)
(print (- (current-milliseconds) currms))))
You can test this by running a thread in the background:
(thread-start! (lambda () (let lp () (print 'ping) (thread-sleep! 2) (lp))))
(sleeper 5.5)
> Of course, having a "real" usleep function would be cleaner than faking it
> with file-select, especially as implementing a usleep procedure is pretty
> trivial:
>
> (define usleep (foreign-lambda int "usleep" unsigned-integer32))
I don't know why sleep(3) was implemented in the posix unit and usleep(3) was
not. thread-sleep! is preferable to either, though, in my opinion.
Jim
- [Chicken-users] (file-select ...) and compiler warnings, J Altfas, 2013/02/17
- Re: [Chicken-users] (file-select ...) and compiler warnings,
Jim Ursetto <=
- Re: [Chicken-users] (file-select ...) and compiler warnings, J Altfas, 2013/02/18
- Re: [Chicken-users] (file-select ...) and compiler warnings, Jim Ursetto, 2013/02/18
- Re: [Chicken-users] (file-select ...) and compiler warnings, J Altfas, 2013/02/18
- Re: [Chicken-users] posix-extras sleep, Jim Ursetto, 2013/02/19
- Re: [Chicken-users] posix-extras sleep, Jim Ursetto, 2013/02/19
- Message not available
- Message not available
- Re: [Chicken-users] posix-extras sleep, J Altfas, 2013/02/20
- Re: [Chicken-users] posix-extras sleep, Jim Ursetto, 2013/02/20
- Re: [Chicken-users] (file-select ...) and compiler warnings, John Cowan, 2013/02/19
Re: [Chicken-users] (file-select ...) and compiler warnings, Felix, 2013/02/18