chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: felix winkelmann
Subject: Re: Re : [Chicken-users] thread-sleep! for less than a second
Date: Mon, 15 Jan 2007 20:21:54 +0100

On 1/13/07, Daishi Kato <address@hidden> 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.000000000 +0100
+++ new-chicken/srfi-18.scm     2007-01-15 20:18:45.000000000 +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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]