Emilio Lopes | 4 Jun 2007 22:00
Picon

thread-running?

Is this a correct definition of `thread-running?'?

    (define (thread-running? thread)
      (and (thread-cell thread) #t))

Is this useful enough to be included in Scheme48?

I noticed a delay between killing/terminating a thread and the above
definition of `thread-running?' returning #f.  Why is that?  (I
couldn't completely understand the code in thread.scm)

--

-- 
Emílio C. Lopes                            Ich leb und weiß nit wie lang,
Munich, Germany                            ich stirb und weiß nit wann,
                                           ich fahr und weiß nit wohin,
                 (Martinus von Biberach)   mich wundert, dass ich fröhlich bin!

Mitchell Wand | 4 Jun 2007 22:57
Favicon

[Scheme Steering Committee announcements] Will Clinger has resigned from the Editors Committee

We are sorry to report that Will Clinger has resigned from the Editors Committee, effective on May 21, 2007.  We accept his resignation with regret and thank him for his service.

According the Charter, the Steering Committee has three months to replace a resigning editor.  The Steering Committee has therefore decided to wait until after the ratification ballot before taking steps to replace him.

[The Steering Committee also apologizes for the delay in announcing Will's resignation.]

For the Steering Committee,
--Mitch Wand

_______________________________________________
Scheme-announcements mailing list
Scheme-announcements <at> lists.ccs.neu.edu
https://lists.ccs.neu.edu/bin/listinfo/scheme-announcements
Michael Sperber | 5 Jun 2007 04:57
Picon

Re: thread-running?


Emilio Lopes <eclig <at> gmx.net> writes:

> Is this a correct definition of `thread-running?'?
>
>     (define (thread-running? thread)
>       (and (thread-cell thread) #t))
>
> Is this useful enough to be included in Scheme48?

I'm not sure - what would you use it for?  It seems to be a recipe for
race conditions.  Moreover, the thread cell also gets cleared when a
thread is scheduled, so it's unlikely to correspond to your notion of
"running".

> I noticed a delay between killing/terminating a thread and the above
> definition of `thread-running?' returning #f.  Why is that?  (I
> couldn't completely understand the code in thread.scm)

You should only see a delay when killing - killing just sends an event
to the thread, instructing it to quit at its own leisure.

--

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

Emilio Lopes | 5 Jun 2007 20:24
Picon

Re: thread-running?

Michael Sperber writes:

> Emilio Lopes <eclig <at> gmx.net> writes:

>> Is this a correct definition of `thread-running?'?
>> 
>> (define (thread-running? thread)
>> (and (thread-cell thread) #t))

> I'm not sure - what would you use it for?

I want to check if a thread is running from the "user" point of view,
meaning: if the thread is eligible to be scheduled again (i.e. not
finished, terminated or killed).

This is unlike `running?' from `threads-internal', which checks if the
thread is running *now*.

I'm working on an application which starts a "server thread" listening
on some port.  At some point in time I want to check if the server
thread for a given port is still running and maybe restart it if it's
not.  Maybe I would be better off checking if there's some socket on
the given port, but this doesn't seem possible right now...

> It seems to be a recipe for race conditions.  Moreover, the thread
> cell also gets cleared when a thread is scheduled, so it's unlikely
> to correspond to your notion of "running".

My first idea was to check the thread continuation, since it's #f after
the thread is finished.  But I then noticed that terminated/killed
threads also have non-#f continuations.

I've came to the following definition, but after some quick tests I
thought that checking the cell was enough.  After reading your
explanation I see it's not.

    (define (thread-running? thread)
      (and (thread-continuation thread)     ; finished?
           (let ((events (thread-events thread)))
             (not (and events
                       (on-queue? events
                                  (enum event-type killed))))) ; killed?
           (thread-cell thread)             ; terminated?
           #t))

Is this OK?

>> I noticed a delay between killing/terminating a thread and the above
>> definition of `thread-running?' returning #f.  Why is that?  (I
>> couldn't completely understand the code in thread.scm)

> You should only see a delay when killing - killing just sends an event
> to the thread, instructing it to quit at its own leisure.

OK, I see.  Thanks for explaining.

--

-- 
Emílio C. Lopes                            Ich leb und weiß nit wie lang,
Munich, Germany                            ich stirb und weiß nit wann,
                                           ich fahr und weiß nit wohin,
                 (Martinus von Biberach)   mich wundert, dass ich fröhlich bin!

Christoph Bauer | 13 Jun 2007 08:21

id-server segfaults

Hi,

OS: Windows XP
Scheme48: 1.6 

With id-server example from the manual scheme48 segfaults 
on the client side.

(define (id-server)
  (let ((socket (open-socket)))
    (display "Waiting on port ")
    (display (socket-port-number socket))
    (newline)
    (let loop ((next-id 0))
      (call-with-values
        (lambda ()
          (socket-accept socket))
        (lambda (in out)
          (display next-id out)
          (close-input-port in)
          (close-output-port out)
          (loop (+ next-id 1)))))))

(define (get-id machine port-number)
  (call-with-values
    (lambda ()
      (socket-client machine port-number))
    (lambda (in out)
      (let ((id (read in)))
        (close-input-port in)
        (close-output-port out)
        id))))

Regards,

Christoph Bauer
--  
LMS Deutschland GmbH - Geschäftsführer: Dr. Ing. Urbain Vandeurzen, Dr.-Ing. Norbert Reimann - Sitz:
Kaiserslautern - Registergericht: HRB Kaiserslautern 3706

Emilio Lopes | 13 Jun 2007 21:02
Picon

Re: id-server segfaults

Christoph Bauer writes:

> OS: Windows XP
> Scheme48: 1.6 

> With id-server example from the manual scheme48 segfaults 
> on the client side.

I might be terribly wrong, but I think the POSIX related features (the
"fun things") don't work on Windows.  You have to use Cygwin for that.

--

-- 
Emílio C. Lopes                            Ich leb und weiß nit wie lang,
Munich, Germany                            ich stirb und weiß nit wann,
                                           ich fahr und weiß nit wohin,
                 (Martinus von Biberach)   mich wundert, dass ich fröhlich bin!

Michael Sperber | 14 Jun 2007 08:18
Picon

Re: id-server segfaults


Emilio Lopes <eclig <at> gmx.net> writes:

> Christoph Bauer writes:
>
>> OS: Windows XP
>> Scheme48: 1.6 
>
>> With id-server example from the manual scheme48 segfaults 
>> on the client side.
>
> I might be terribly wrong, but I think the POSIX related features (the
> "fun things") don't work on Windows.  You have to use Cygwin for that.

Sockets should work, though.  I'll get to it, but probably not before
next week.

--

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

Christoph Bauer | 14 Jun 2007 08:18

regexp on windows

Hi,

try this on windows:

> (match (text "abc") "abc")

Bug: bad procedure
     call-error:
     (#{Procedure 8794 (call-imported-binding in external-calls)} #{Imported-binding
"posix_compile_regexp"} #{Byte-vector 10} #t #f #t ---)

Regards,

Christoph Bauer
--  
LMS Deutschland GmbH - Geschäftsführer: Dr. Ing. Urbain Vandeurzen, Dr.-Ing. Norbert Reimann - Sitz:
Kaiserslautern - Registergericht: HRB Kaiserslautern 3706

Michael Sperber | 14 Jun 2007 09:57
Picon

Re: regexp on windows


"Christoph Bauer" <Christoph.Bauer <at> lmsintl.com> writes:

> Hi,
>
> try this on windows:
>
>> (match (text "abc") "abc")
>
> Bug: bad procedure
>      call-error:
>      (#{Procedure 8794 (call-imported-binding in external-calls)} #{Imported-binding
"posix_compile_regexp"} #{Byte-vector 10} #t #f #t ---)

Regexps aren't supported on Windows.  (We just link to the POSIX
library.)  If you really need them, you can make them work as described
here:

http://article.gmane.org/gmane.lisp.scheme.scheme48/1658/match=regex

If you need a precompiled DLL, let me know.  (The one linked to in the
message doesn't work with 1.6.)

--

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

Ed Watkeys | 22 Jun 2007 21:49
Favicon
Gravatar

Forking safely

Hi,

I was conversing with Taylor about proper use of `fork' in
multi-threaded applications, and thought I'd code up a procedure that
captured the does the right thing (or something approaching the right
thing) so that it can be readily re-used.

(define (safe-fork parent-proc child-thunk)
  (let ((interrupts (set-enabled-interrupts! no-interrupts)))
    (cond ((fork) =>
           (lambda (child)
             (set-enabled-interrupts! interrupts)
             (parent-proc child)))
          (else
           (child-thunk)))))

On the off chance that you want to re-enabled interrupts in the child,
you may want to consider this variant:

(define (safe-fork* parent-proc child-proc)
  (let ((interrupts (set-enabled-interrupts! no-interrupts)))
    (cond ((fork) =>
           (lambda (child)
             (set-enabled-interrupts! interrupts)
             (parent-proc child)))
          (else
           (child-proc interrupts)))))

The former procedure can be found along with a big pile of other
possibly useful S48 code in the Magic source code repository,
available at the following URL:

http://magic.xmog.com/darcs/magic/

`Safe-fork' lives in the following source file:

http://magic.xmog.com/darcs/magic/scm/filters.scm

Regards,
Ed

--

-- 
Ed Watkeys (http://poseur.com/)
"Hemingway once said, 'The world is a fine place
and worth fighting for.' I agree with the second part."


Gmane