Aki Helin | 9 Oct 2003 14:15
Picon
Picon

Trouble with handles and threads

Hi, 

Below is a small program that is supposed to serve one
web page on port 10001. The page is served by a thread 
spawned when the socket connection is established. The 
thread uses 'try' to print each content line. Calling 
try is supposed to always return, and in case of any 
error #f should be returned. The printing thread prints 
the page until try returns #f, in which case the thread
is terminated.

The trouble is that unless try is traced, scheme48vm 
still keeps using 100% of cpu after the thread is 
terminated.  Trying a few variations of this always 
resulted in a similar problem. For example cpu load 
would remain in 100% after terminate-current-thread 
finished unless the parameters of try were printed.

This example is taken from across a few modules that
make up a web server and some cgi applications. They 
have run under scsh for about 6 months now without 
any trouble. 

I wonder if this is a bug or a feature.

------8<-------

,open sockets ascii handle threads

(define (print . args) 
(Continue reading)

Richard Kelsey | 9 Oct 2003 16:07
Favicon

Re: Trouble with handles and threads

   Date: Thu, 9 Oct 2003 15:15:05 +0300 (EEST)
   From: Aki Helin <ahelin <at> mail.student.oulu.fi>

   The trouble is that unless try is traced, scheme48vm 
   still keeps using 100% of cpu after the thread is 
   terminated.

Which version of what program (Scheme 48 or Scsh) are you using?

                                     -Richard

Aki Helin | 9 Oct 2003 16:31
Picon
Picon

Re: Trouble with handles and threads


>    Date: Thu, 9 Oct 2003 15:15:05 +0300 (EEST)
>    From: Aki Helin <ahelin <at> mail.student.oulu.fi>
>
>    The trouble is that unless try is traced, scheme48vm
>    still keeps using 100% of cpu after the thread is
>    terminated.
>
> Which version of what program (Scheme 48 or Scsh) are you using?

I have Scheme48 0.57 and Scsh 0.6.4.

--
aki helin

Aki Helin | 9 Oct 2003 17:54
Picon
Picon

More on threads and handles


I apparently forgot the '-t' from mail which generates the To field.

Sorry about that.

Scheme 48 version is 0.57 and Scsh version is 0.6.4.

--
aki helin

Richard Kelsey | 12 Oct 2003 20:15
Favicon

Re: Trouble with handles and threads

   Date: Thu, 9 Oct 2003 15:31:33 +0300 (EEST)
   From: Aki Helin <ahelin <at> mail.student.oulu.fi>

   Below is a small program that is supposed to serve one
   web page on port 10001.  [...]

   The trouble is that unless try is traced, scheme48vm 
   still keeps using 100% of cpu after the thread is 
   terminated.

Yes.  This is a bug.  If you replace the definition of MAKE-FORCER
in scheme/rts/port-buffer.scm it should fix the problem.  You will
need to do 'make build/initial.image' and then 'make scheme48.image'
for the change to take effect (in Scheme48; Scsh probably requires
more).

  (define (make-forcer buffer-emptier!)
    (lambda (port necessary?)
      (with-new-proposal (lose)
        (cond ((not (open-output-port? port))
               (if necessary?
                   (begin
                     (remove-current-proposal!)
                     (call-error "invalid argument" force-output port)))
                   (unspecific))
              ((< 0 (provisional-port-index port))
               (set-port-flushed?! port #t)
               (if (or (not (buffer-emptier! port necessary?))
                       necessary?)
                   (lose)))))))
(Continue reading)

shredder | 15 Oct 2003 04:05
Favicon

Problem with scheme48 printing circular constructs

Hi,

I'm using scheme48 to learn SICP. 

If I construct some circular constructs, such as procedure definitions in Chapter 4, and if I evaluate
"the-global-environment", scheme48 would go into infinite loop printing the value. Another case
arises in evaluating a record type of SRFI-9.

Is there are way to print the circular constructs safely? MzScheme can use placeholders such as #1, #2 to
denote the circular links. Is there a similar mechanism in Scheme48?

Another problem is how to limit the accuracy of floating point numbers. The precision is too high and it's
slow when doing numerical calculations.

Thanks.

Darren Bane | 17 Oct 2003 21:05
Picon

Re: Problem with scheme48 printing circular constructs

shredder <at> sohu.com wrote:
> Hi,
> 
> I'm using scheme48 to learn SICP. 
> 
> If I construct some circular constructs, such as procedure
> definitions
> in Chapter 4, and if I evaluate "the-global-environment", scheme48 would
> go into infinite loop printing the value.  Another case arises in
> evaluating a record type of SRFI-9.
> 
> Is there are way to print the circular constructs safely? MzScheme
> can
> use placeholders such as #1, #2 to denote the circular links. Is there a
> similar mechanism in Scheme48?

This isn't really a bug. If you read SRFI-38 from
http://srfi.schemers.org/srfi-38/srfi-38.html, apparently R5RS says that
write is undefined for circular data structures.

You could use the implementation in SRFI-38 to write a shared structure
if you like.

> Another problem is how to limit the accuracy of floating point
> numbers. The precision is too high and it's slow when doing numerical
> calculations.

I'm unfamiliar with the details of the numerics implementation, but
assuming that the VM implements them using the native C float or double
type, this is hardware accelerated.  Nowadays, single-precision IEEE
(Continue reading)

Jonathan A Rees | 17 Oct 2003 21:25
Favicon

Re: Problem with scheme48 printing circular constructs

   Date: Fri, 17 Oct 2003 20:05:17 +0100
   From: Darren Bane <pangur <at> utvinternet.ie>

   This isn't really a bug. If you read SRFI-38 from
   http://srfi.schemers.org/srfi-38/srfi-38.html, apparently R5RS says that
   write is undefined for circular data structures.

Au contraire - I would call this a user interface bug.  R5RS says
nothing about how a user/programmer interacts with an implementation.
I would argue that it's the UI's job to be of service, and to produce
information that can be of value (so to speak) to the user.  This
principle precludes blind use of a naive 'write' procedure and
consequent result-display explosion or nontermination.

In Scheme 48, the bug results from a conflicting principle of economy
of implementation.  Add an always-terminating printer, and both the UI
and the I/O system become hairier.

Jonathan

Richard Kelsey | 17 Oct 2003 22:15
Favicon

Re: Problem with scheme48 printing circular constructs

   Date: Fri, 17 Oct 2003 20:05:17 +0100
   From: Darren Bane <pangur <at> utvinternet.ie>
   References: <1777775.1066183531098.JavaMail.postfix <at> mx28.mail.sohu.com>

   shredder <at> sohu.com wrote:
   > Another problem is how to limit the accuracy of floating point
   > numbers. The precision is too high and it's slow when doing numerical
   > calculations.

   I'm unfamiliar with the details of the numerics implementation, but
   assuming that the VM implements them using the native C float or double
   type, this is hardware accelerated.

For reasons I don't want to go into, Scheme 48 by default implements
inexact numbers as infinite-precision ratios.  To get the faster but
less precise IEEE doubles you need to do:

  ,load-package floatnums
                                     -Richard


Gmane