chicken-janitors
[Top][All Lists]
Advanced

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

Re: [Chicken-janitors] #1356: weak-locatives references return #f when i


From: Chicken Trac
Subject: Re: [Chicken-janitors] #1356: weak-locatives references return #f when it shouldn't
Date: Sat, 22 Apr 2017 08:54:46 -0000

#1356: weak-locatives references return #f when it shouldn't
-----------------------------------+--------------------
            Reporter:  kristianlm  |      Owner:
                Type:  defect      |     Status:  new
            Priority:  major       |  Milestone:  4.13.0
           Component:  unknown     |    Version:  4.12.0
          Resolution:              |   Keywords:
Estimated difficulty:              |
-----------------------------------+--------------------

Comment (by kristianlm):

 After some thinking, I realize this bug-report should be the other way
 around. So my previous claim is wrong:

 {{{
 running the program below should output this:
 }}}


 The correct behaviour is that the thread and its REFERENCE gets garbage
 collected and the weak-reference returning {{{#f}}}. Because nobody is
 holding onto the condition-variable, the thread can never resume, and it
 can and should disappear from memory! This allows me to do cool things
 like [https://github.com/Adellica/chicken-
 gochan/blob/ea4e3f34f5090b61e4d34c451efacc13ec0bbafc/tests/thread-leak-
 test.scm this]!

 So, that leaves us with why the thread dot not ''always'' get garbage-
 collected. I can't trigger the following finalizers consistently:

 {{{
 (use srfi-18 miscmacros)

 (repeat 1
  (set-finalizer!
   (thread-start! (lambda () (mutex-unlock! (make-mutex) (make-condition-
 variable))))
   (lambda (x) (print "blocked thread gced!")))

  (set-finalizer!
   (thread-start! (lambda () #f))
   (lambda (x) (print "exited thread gced!")))

  (set-finalizer!
   (vector 1 2 3)
   (lambda (x) (print "vector gced"))))

 (thread-sleep! 1) ;; ensure other thread blocks on cv
 (gc #t)           ;; major gc and run all finalizers
 (thread-sleep! 1) ;; ensure finalizers get run
 }}}

 That gives me (on CHICKEN 4.12 at least):

 {{{
 $ csc /tmp/finalizer-test.scm  ; and /tmp/finalizer-test
 vector gced
 exited thread gced!
 }}}

 No {{{blocked thread gced!}}} :-( However, if I change to (repeat 1000
 ...) , the {{{blocked thread}}} finalizers also run, so that's great! But
 why won't it run with only 1 {{{blocked thread}}} started?

--
Ticket URL: <https://bugs.call-cc.org/ticket/1356#comment:3>
CHICKEN Scheme <https://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.

reply via email to

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