guile-user
[Top][All Lists]
Advanced

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

Re: racing srfi-18 threads


From: Tristan Colgate
Subject: Re: racing srfi-18 threads
Date: Fri, 6 Nov 2009 14:52:44 +0000

After some further investigation, this seems to be a compile/vm issue.

$ touch test-race
$ GUILE_AUTO_COMPILE=0 guile test-race

yields the correct result. But if I run without inhibiting the auto
compilation this
fail as before.Any subsequent runs, with or without GUILE_AUTO_COMPILE set
then fail.

A similar, though much simpler, test case exhibits the same problem.
I'll raise a bug. report and
include a log of the issue.

2009/11/6 Tristan Colgate <address@hidden>:
> Hi All,
>
>  I've been experimenting with guile-1.9 (latest git)  srfi-18 support.
> I'm trying
> to implement a race between threads. I've written a macro that take a
> routine and a list of args, starts a thread for each arg and runs the
> routine with that argument. The result  returned should be the return
> result of the first thread to return. I was originally using some of
> guile other thread primitives (monitor in particular), but have
> stripped those out in order to try testing against other schemes.
>
>  Chicken currently gives the "correct" result, but that uses
> cooperative threading. Guile launches threads, I can see them with a
> ps -efL,  but they never seem to start (even after the thread-start!).
>
>  The code is as follows....
>
> (require-extension (srfi 18))
>
> (define-syntax race-each
>  (syntax-rules ()
>  ((_ func parargs)
>  (let* ((result #f)
>         (result-ready (make-condition-variable))
>         (junktex (make-mutex))
>         (junk    (mutex-lock! junktex))
>         (resulttex (make-mutex))
>         (dotask (lambda(arg)
>                    (let ((thisresult (func arg)))
>                      (with-exception-handler
>                        (lambda(ev)
>                          (thread-terminate! (current-thread)))
>                        (lambda() (mutex-lock! resulttex)))
>                      (set! result thisresult)
>                      (condition-variable-signal! result-ready)
>                      (thread-terminate! (current-thread)))))
>         (threads (map (lambda(x)
>                         (thread-start! (make-thread (lambda()
>                                                        (dotask x)))))
> parargs)))
>     (mutex-unlock! junktex result-ready)
>     (map (lambda(old-thread) (thread-terminate! old-thread)) threads)
>     result))))
>
> (display
>  (race-each
>   (lambda(value)
>     (format #t "In thread~%")
>     (thread-sleep! (seconds->time (+ (time->seconds (current-time)) value)))
>     value)
>   '(3 5 8 9 2)))
>
>
> --
> Tristan Colgate-McFarlane
> ----
>  "You can get all your daily vitamins from 52 pints of guiness, and a
> glass of milk"
>



-- 
Tristan Colgate-McFarlane
----
  "You can get all your daily vitamins from 52 pints of guiness, and a
glass of milk"




reply via email to

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