Arc Forumnew | comments | leaders | submitlogin
2 points by lark 4069 days ago | link | parent

Thanks.

Shouldn't Arc provide something like pthread_join? A function that wakes up the thread that waits -- rather than continually checking for all threads to exit?



2 points by akkartik 4068 days ago | link

I see racket does provide thread-wait:

http://docs.racket-lang.org/reference/threads.html#%28part._...

Should be easy to add to arc. Can you submit a pull request if you do so?

-----

3 points by lark 4063 days ago | link

Thanks so much for the link, that was it.

  $ diff -prauN ac.scm ac.scm.wait 
  --- ac.scm	2013-09-28 10:04:00.907266192 -0400
  +++ ac.scm.wait	2013-09-28 10:03:55.811266793 -0400
  @@ -1035,6 +1035,7 @@
   (xdef new-thread thread)
   (xdef kill-thread kill-thread)
   (xdef break-thread break-thread)
  +(xdef wait-thread thread-wait)
   (xdef current-thread current-thread)
   
   (define (wrapnil f) (lambda args (apply f args) 'nil))
And an example using wait-thread:

  (def th-test() ; how to use wait-thread                                              
    (withs (counter 0 allthreads nil)
           (while (< counter 4)
                  (withs (this nil localcnt counter)
                         (= this (thread (do (prn "thread " localcnt)
                                             (sleep 2))))
                         (push this allthreads))
                  (++ counter))
           (each th allthreads
                 (withs (thisthread nil)
                        (= thisthread (wait-thread th))
                        (prn "thread " thisthread " finished")))))

-----

2 points by akkartik 4063 days ago | link

Just tried your example. Nice!

-----