Re: Re : [Chicken-users] thread-sleep! for less than a second

2007-01-17 Thread felix winkelmann

On 1/16/07, Daishi Kato <[EMAIL PROTECTED]> wrote:


Or, since timeout for these procedures including thread-sleep! can be
a time object,
introducing time->milliseconds and milliseconds->time would be sufficient.


It's now checked into the darcs repo, here the patch:

--- old-chicken/srfi-18.scm 2007-01-17 11:38:01.609268408 +0100
+++ new-chicken/srfi-18.scm 2007-01-17 11:38:01.613267800 +0100
@@ -1,4 +1,4 @@
-;;; srfi-18.scm - Simple thread unit - felix
+ srfi-18.scm - Simple thread unit - felix
;
; Copyright (c) 2000-2007, Felix L. Winkelmann
; All rights reserved.
@@ -121,6 +121,11 @@
  (##sys#check-structure tm 'time 'time->seconds)
  (+ (##sys#slot tm 2) (/ (##sys#slot tm 3) 1000)) )

+(define (time->milliseconds tm)
+  (##sys#check-structure tm 'time 'time->milliseconds)
+  (+ (inexact->exact (* (- (##sys#slot tm 2) C_startup_time_seconds) 1000))
+ (##sys#slot tm 3) ) )
+
(define (seconds->time n)
  (##sys#check-number n 'seconds->time)
  (let* ([n2 (max 0 (- n C_startup_time_seconds))] ; seconds since startup
@@ -128,6 +133,11 @@
 [n3 (inexact->exact (truncate (+ (* n2 1000) ms)))] ) ;
milliseconds since startup
(##sys#make-structure 'time n3 (truncate n) (inexact->exact ms)) ) )

+(define (milliseconds->time nms)
+  (##sys#check-exact nms 'milliseconds->time)
+  (let ((s (+ C_startup_time_seconds (/ nms 1000
+(##sys#make-structure 'time nms s 0) ) )
+
(define (time? x) (##sys#structure? x 'time))

(define srfi-18:time? time?)
@@ -281,16 +291,16 @@
(##sys#setslot thread 3 'ready)
(##sys#add-to-ready-queue thread) ) )

-(define thread-sleep!
-  (lambda (tm)
-(unless tm (##sys#signal-hook #:type-error 'thread-sleep!
"invalid timeout argument" tm))
+(define (thread-sleep! tm)
+  (define (sleep limit loc)
(##sys#call-with-current-continuation
 (lambda (return)
-   (let ([limit (##sys#compute-time-limit tm)]
-[ct ##sys#current-thread] )
+   (let ((ct ##sys#current-thread))
 (##sys#setslot ct 1 (lambda () (return (##core#undefined
 (##sys#thread-block-for-timeout! ct limit)
-(##sys#schedule) ) ) ) ) )
+(##sys#schedule) ) ) ) )
+  (unless tm (##sys#signal-hook #:type-error 'thread-sleep! "invalid
timeout argument" tm))
+  (sleep (##sys#compute-time-limit tm) 'thread-sleep!) )


;;; Mutexes:


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re : Re : [Chicken-users] thread-sleep! for less than a second

2007-01-16 Thread minh thu

2007/1/15, felix winkelmann <[EMAIL PROTECTED]>:

On 1/13/07, Daishi Kato <[EMAIL PROTECTED]> wrote:
> Hi,
>
> That was something that I could not notice either at first.
> Another issue for me is that I want to declare fixnum
> when all other procedures are fixnum arithmetic.
> So, I wished thread-sleep-millis!
> Any workaround for this? Maybe making a tiny egg for this?
>

I have added it (called `thread-sleep!/ms') to srfi-18. Here is the patch:

diff -rN -u old-chicken/srfi-18.scm new-chicken/srfi-18.scm
--- old-chicken/srfi-18.scm 2007-01-15 20:18:45.0 +0100
+++ new-chicken/srfi-18.scm 2007-01-15 20:18:45.0 +0100
@@ -281,16 +281,25 @@
 (##sys#setslot thread 3 'ready)
 (##sys#add-to-ready-queue thread) ) )

-(define thread-sleep!
-  (lambda (tm)
-(unless tm (##sys#signal-hook #:type-error 'thread-sleep!
"invalid timeout argument" tm))
+(define thread-sleep!)
+(define thread-sleep!/ms)
+
+(let ()
+  (define (sleep limit loc)
 (##sys#call-with-current-continuation
  (lambda (return)
-   (let ([limit (##sys#compute-time-limit tm)]
-[ct ##sys#current-thread] )
+   (let ((ct ##sys#current-thread))
 (##sys#setslot ct 1 (lambda () (return (##core#undefined
 (##sys#thread-block-for-timeout! ct limit)
-(##sys#schedule) ) ) ) ) )
+(##sys#schedule) ) ) ) )
+  (set! thread-sleep!
+(lambda (tm)
+  (unless tm (##sys#signal-hook #:type-error 'thread-sleep!
"invalid timeout argument" tm))
+  (sleep (##sys#compute-time-limit tm)) ) )
+  (set! thread-sleep!/ms
+(lambda (ms)
+  (##sys#check-exact ms 'thread-sleep!/ms)
+  (sleep (fx+ (##sys#fudge 16) ms)) ) ) )


cheers,
felix



Thanks,
thu


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: Re : [Chicken-users] thread-sleep! for less than a second

2007-01-16 Thread felix winkelmann

On 1/16/07, Daishi Kato <[EMAIL PROTECTED]> wrote:


Sure, and done.


Thanks.


With the latter solution, we don't need thread-sleep!/ms, right?


Exactly.


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: Re : [Chicken-users] thread-sleep! for less than a second

2007-01-15 Thread Daishi Kato

On 1/16/07, felix winkelmann <[EMAIL PROTECTED]> wrote:

On 1/16/07, Daishi Kato <[EMAIL PROTECTED]> wrote:
>
> BTW, timeout is also used for thread-join!, mutex-lock! and
> mutex-unlock! in srfi-18.
> It'd be more consistent to have */ms procedures for these above.
> Or, since timeout for these procedures including thread-sleep! can be
> a time object,
> introducing time->milliseconds and milliseconds->time would be sufficient.
>

I prefer the latter solution. Could you write a ticket at
http://trac.callcc.org for
this?


Sure, and done.
With the latter solution, we don't need thread-sleep!/ms, right?

--daishi


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: Re : [Chicken-users] thread-sleep! for less than a second

2007-01-15 Thread felix winkelmann

On 1/16/07, Daishi Kato <[EMAIL PROTECTED]> wrote:


BTW, timeout is also used for thread-join!, mutex-lock! and
mutex-unlock! in srfi-18.
It'd be more consistent to have */ms procedures for these above.
Or, since timeout for these procedures including thread-sleep! can be
a time object,
introducing time->milliseconds and milliseconds->time would be sufficient.



I prefer the latter solution. Could you write a ticket at
http://trac.callcc.org for
this?


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Fwd: Re : [Chicken-users] thread-sleep! for less than a second

2007-01-15 Thread Daishi Kato

This is supposed to go the chicken ML.

-- Forwarded message --
From: Daishi Kato <[EMAIL PROTECTED]>
Date: Jan 16, 2007 10:43 AM
Subject: Re: Re : [Chicken-users] thread-sleep! for less than a second
To: felix winkelmann <[EMAIL PROTECTED]>


Thanks a lot!

BTW, timeout is also used for thread-join!, mutex-lock! and
mutex-unlock! in srfi-18.
It'd be more consistent to have */ms procedures for these above.
Or, since timeout for these procedures including thread-sleep! can be
a time object,
introducing time->milliseconds and milliseconds->time would be sufficient.

Comments are welcome.
Daishi

On 1/16/07, felix winkelmann <[EMAIL PROTECTED]> wrote:

On 1/13/07, Daishi Kato <[EMAIL PROTECTED]> wrote:
> Hi,
>
> That was something that I could not notice either at first.
> Another issue for me is that I want to declare fixnum
> when all other procedures are fixnum arithmetic.
> So, I wished thread-sleep-millis!
> Any workaround for this? Maybe making a tiny egg for this?
>

I have added it (called `thread-sleep!/ms') to srfi-18. Here is the patch:

diff -rN -u old-chicken/srfi-18.scm new-chicken/srfi-18.scm
--- old-chicken/srfi-18.scm 2007-01-15 20:18:45.0 +0100
+++ new-chicken/srfi-18.scm 2007-01-15 20:18:45.0 +0100
@@ -281,16 +281,25 @@
 (##sys#setslot thread 3 'ready)
 (##sys#add-to-ready-queue thread) ) )

-(define thread-sleep!
-  (lambda (tm)
-(unless tm (##sys#signal-hook #:type-error 'thread-sleep!
"invalid timeout argument" tm))
+(define thread-sleep!)
+(define thread-sleep!/ms)
+
+(let ()
+  (define (sleep limit loc)
 (##sys#call-with-current-continuation
  (lambda (return)
-   (let ([limit (##sys#compute-time-limit tm)]
-[ct ##sys#current-thread] )
+   (let ((ct ##sys#current-thread))
 (##sys#setslot ct 1 (lambda () (return (##core#undefined
 (##sys#thread-block-for-timeout! ct limit)
-(##sys#schedule) ) ) ) ) )
+(##sys#schedule) ) ) ) )
+  (set! thread-sleep!
+(lambda (tm)
+  (unless tm (##sys#signal-hook #:type-error 'thread-sleep!
"invalid timeout argument" tm))
+  (sleep (##sys#compute-time-limit tm)) ) )
+  (set! thread-sleep!/ms
+(lambda (ms)
+  (##sys#check-exact ms 'thread-sleep!/ms)
+  (sleep (fx+ (##sys#fudge 16) ms)) ) ) )


cheers,
felix




___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: Re : [Chicken-users] thread-sleep! for less than a second

2007-01-15 Thread felix winkelmann

On 1/13/07, Daishi Kato <[EMAIL PROTECTED]> wrote:

Hi,

That was something that I could not notice either at first.
Another issue for me is that I want to declare fixnum
when all other procedures are fixnum arithmetic.
So, I wished thread-sleep-millis!
Any workaround for this? Maybe making a tiny egg for this?



I have added it (called `thread-sleep!/ms') to srfi-18. Here is the patch:

diff -rN -u old-chicken/srfi-18.scm new-chicken/srfi-18.scm
--- old-chicken/srfi-18.scm 2007-01-15 20:18:45.0 +0100
+++ new-chicken/srfi-18.scm 2007-01-15 20:18:45.0 +0100
@@ -281,16 +281,25 @@
(##sys#setslot thread 3 'ready)
(##sys#add-to-ready-queue thread) ) )

-(define thread-sleep!
-  (lambda (tm)
-(unless tm (##sys#signal-hook #:type-error 'thread-sleep!
"invalid timeout argument" tm))
+(define thread-sleep!)
+(define thread-sleep!/ms)
+
+(let ()
+  (define (sleep limit loc)
(##sys#call-with-current-continuation
 (lambda (return)
-   (let ([limit (##sys#compute-time-limit tm)]
-[ct ##sys#current-thread] )
+   (let ((ct ##sys#current-thread))
(##sys#setslot ct 1 (lambda () (return (##core#undefined
(##sys#thread-block-for-timeout! ct limit)
-(##sys#schedule) ) ) ) ) )
+(##sys#schedule) ) ) ) )
+  (set! thread-sleep!
+(lambda (tm)
+  (unless tm (##sys#signal-hook #:type-error 'thread-sleep!
"invalid timeout argument" tm))
+  (sleep (##sys#compute-time-limit tm)) ) )
+  (set! thread-sleep!/ms
+(lambda (ms)
+  (##sys#check-exact ms 'thread-sleep!/ms)
+  (sleep (fx+ (##sys#fudge 16) ms)) ) ) )


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: Re : [Chicken-users] thread-sleep! for less than a second

2007-01-12 Thread Daishi Kato

Hi,

That was something that I could not notice either at first.
Another issue for me is that I want to declare fixnum
when all other procedures are fixnum arithmetic.
So, I wished thread-sleep-millis!
Any workaround for this? Maybe making a tiny egg for this?

Daishi

On 1/13/07, minh thu <[EMAIL PROTECTED]> wrote:

2007/1/12, Kon Lovett <[EMAIL PROTECTED]>:
> On Jan 12, 2007, at 1:36 PM, minh thu wrote:
>
> > Hi,
> >
> > Question again, my apologies ;)
> >
> > Is it possible to have a thread sleep some milliseconds ?
>
> thread-sleep! (the seconds do not need to be a whole number)
Tks, I didn't see it in the chicken doc or srfi-18.
thu


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users




___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re : [Chicken-users] thread-sleep! for less than a second

2007-01-12 Thread minh thu

2007/1/12, Kon Lovett <[EMAIL PROTECTED]>:

On Jan 12, 2007, at 1:36 PM, minh thu wrote:

> Hi,
>
> Question again, my apologies ;)
>
> Is it possible to have a thread sleep some milliseconds ?

thread-sleep! (the seconds do not need to be a whole number)

Tks, I didn't see it in the chicken doc or srfi-18.
thu


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] thread-sleep! for less than a second

2007-01-12 Thread Kon Lovett

On Jan 12, 2007, at 1:36 PM, minh thu wrote:


Hi,

Question again, my apologies ;)

Is it possible to have a thread sleep some milliseconds ?


thread-sleep! (the seconds do not need to be a whole number)



I want to have a thread poll xlib for some events but not in tight
loop neither only every second (thus something in between). I guess
also than thread-yield! gives cpu to other threads but still makes a
tight loop in case the other threads want to sleep!

I can't use c sleeping function, otherwise the whole chicken runtime
will go to bed.

Is there any workaround ? Maybe I can add the feature to chicken  
itself ?


Thanks,
thu


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users




___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] thread-sleep! for less than a second

2007-01-12 Thread minh thu

Hi,

Question again, my apologies ;)

Is it possible to have a thread sleep some milliseconds ?

I want to have a thread poll xlib for some events but not in tight
loop neither only every second (thus something in between). I guess
also than thread-yield! gives cpu to other threads but still makes a
tight loop in case the other threads want to sleep!

I can't use c sleeping function, otherwise the whole chicken runtime
will go to bed.

Is there any workaround ? Maybe I can add the feature to chicken itself ?

Thanks,
thu


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users